multisite - Remove filter from WordPress Plugin

I am using a plugin called that causes all of distributed posts to have a rel=canonical back to the source. I reached ou

I am using a plugin called that causes all of distributed posts to have a rel=canonical back to the source. I reached out to the developers and they told me the following:

By default, canonical URL of distributed post will point to original content, which corresponds to SEO best practices. This can be overridden by extending Distributor with custom code and removing Distributor's default front end canonical URL filtering (look for 'get_canonical_url' and 'wpseo_canonical').

Here is their code:

public static function canonicalize_front_end() {
    add_filter( 'get_canonical_url', array( '\Distributor\InternalConnections\NetworkSiteConnection', 'canonical_url' ), 10, 2 );
    add_filter( 'wpseo_canonical', array( '\Distributor\InternalConnections\NetworkSiteConnection', 'wpseo_canonical_url' ) );
    add_filter( 'wpseo_opengraph_url', array( '\Distributor\InternalConnections\NetworkSiteConnection', 'wpseo_og_url' ) );
    add_filter( 'the_author', array( '\Distributor\InternalConnections\NetworkSiteConnection', 'the_author_distributed' ) );
    add_filter( 'author_link', array( '\Distributor\InternalConnections\NetworkSiteConnection', 'author_posts_url_distributed' ), 10, 3 );
}

I went into my child theme functions.php file and added the following:

  remove_filter( 'get_canonical_url', array( '\Distributor\InternalConnections\NetworkSiteConnection', 'canonical_url' ), 10, 2 );
  remove_filter( 'wpseo_canonical', array( '\Distributor\InternalConnections\NetworkSiteConnection', 'wpseo_canonical_url' ) );

It doesn't seem to work for me. Any thoughts?

I am using a plugin called that causes all of distributed posts to have a rel=canonical back to the source. I reached out to the developers and they told me the following:

By default, canonical URL of distributed post will point to original content, which corresponds to SEO best practices. This can be overridden by extending Distributor with custom code and removing Distributor's default front end canonical URL filtering (look for 'get_canonical_url' and 'wpseo_canonical').

Here is their code:

public static function canonicalize_front_end() {
    add_filter( 'get_canonical_url', array( '\Distributor\InternalConnections\NetworkSiteConnection', 'canonical_url' ), 10, 2 );
    add_filter( 'wpseo_canonical', array( '\Distributor\InternalConnections\NetworkSiteConnection', 'wpseo_canonical_url' ) );
    add_filter( 'wpseo_opengraph_url', array( '\Distributor\InternalConnections\NetworkSiteConnection', 'wpseo_og_url' ) );
    add_filter( 'the_author', array( '\Distributor\InternalConnections\NetworkSiteConnection', 'the_author_distributed' ) );
    add_filter( 'author_link', array( '\Distributor\InternalConnections\NetworkSiteConnection', 'author_posts_url_distributed' ), 10, 3 );
}

I went into my child theme functions.php file and added the following:

  remove_filter( 'get_canonical_url', array( '\Distributor\InternalConnections\NetworkSiteConnection', 'canonical_url' ), 10, 2 );
  remove_filter( 'wpseo_canonical', array( '\Distributor\InternalConnections\NetworkSiteConnection', 'wpseo_canonical_url' ) );

It doesn't seem to work for me. Any thoughts?

Share Improve this question edited Dec 3, 2019 at 14:03 butlerblog 5,1213 gold badges28 silver badges44 bronze badges asked Dec 2, 2019 at 22:40 user3096584user3096584 212 bronze badges 1
  • Are you certain your functions.php file is being called? Assuming this isn't the issue, your remove_filter statements are probably executing before the plugin adds the filters. Look at the plugin code and find where the canonicalize_front_end is called and remove the filters after that. The order of operations in WP trips up many so finding where in the process functions are firing is key. – jdm2112 Commented Dec 3, 2019 at 3:02
Add a comment  | 

1 Answer 1

Reset to default 0

You can't just add remove_filter() and have it remove the filters.

remove_filter() always has to happen after the callback you want to remove is added. Your remove_filter() call is most likely run before the plugin's add_filter().

You need to find where/when that plugin hooks canonicalize_front_end() and then run your removal accordingly (i.e. at or after that).

For example, if canonicalize_front_end() is run at the init action, then you could do the following:

add_action( 'init', 'my_remove_filter' );
function my_remove_filter() {
    remove_filter( 'get_canonical_url', array( '\Distributor\InternalConnections\NetworkSiteConnection', 'canonical_url' ), 10, 2 );
    remove_filter( 'wpseo_canonical', array( '\Distributor\InternalConnections\NetworkSiteConnection', 'wpseo_canonical_url' ) );
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744944477a4602528.html

相关推荐

  • multisite - Remove filter from WordPress Plugin

    I am using a plugin called that causes all of distributed posts to have a rel=canonical back to the source. I reached ou

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信