最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

url rewriting - Disabling Yoast, All-in-One, and Rank Math on Certain Pages within a Plugin

programmeradmin4浏览0评论

I developed a custom plugin for a site that is using URL rewriting within WordPress to create several dynamic pages. When one of these custom pages is loaded, I'm using the following functions and filters to create custom page titles and meta descriptions:

// page title
add_filter('pre_get_document_title',array(&$this,'mp_custom_page_title'));
add_filter('document_title_parts',array(&$this,'mp_custom_change_document_title_parts'));

// meta tags
add_filter('description_tag_filter',array(&$this,'mp_custom_description_metatag'));
add_action('wp_head',array(&$this,'mp_custom_metatag_display'),0);

This works beautifully to create custom, dynamically generated page titles and meta descriptions. That is, until I enable ANY SEO plugin (Yoast, All-in-One, Rank Math, etc.).

I need to use these plugins on the blog and standard pages on the website, but I want to disable them from running only when one of my custom pages/URLs is running. I came across this code:

// JetPack
remove_action('wp_head','jetpack_og_tags');
// Yoast SEO
if (defined('WPSEO_VERSION'))
{
    global $wpseo_front;
    remove_action('wp_head',array($wpseo_front,'head'),1);
}
// All-In-One SEO
if (defined('AIOSEOP_VERSION'))
{
    global $aiosp;
    remove_action('wp_head',array($aiosp,'wp_head'));
}

I've tried running it within the function that calls the custom page, as well as the functions mp_custom_page_title and mp_custom_metatag_display, but no luck.

How can I disable these plugins on these pages? Any insight is greatly appreciated!

I developed a custom plugin for a site that is using URL rewriting within WordPress to create several dynamic pages. When one of these custom pages is loaded, I'm using the following functions and filters to create custom page titles and meta descriptions:

// page title
add_filter('pre_get_document_title',array(&$this,'mp_custom_page_title'));
add_filter('document_title_parts',array(&$this,'mp_custom_change_document_title_parts'));

// meta tags
add_filter('description_tag_filter',array(&$this,'mp_custom_description_metatag'));
add_action('wp_head',array(&$this,'mp_custom_metatag_display'),0);

This works beautifully to create custom, dynamically generated page titles and meta descriptions. That is, until I enable ANY SEO plugin (Yoast, All-in-One, Rank Math, etc.).

I need to use these plugins on the blog and standard pages on the website, but I want to disable them from running only when one of my custom pages/URLs is running. I came across this code:

// JetPack
remove_action('wp_head','jetpack_og_tags');
// Yoast SEO
if (defined('WPSEO_VERSION'))
{
    global $wpseo_front;
    remove_action('wp_head',array($wpseo_front,'head'),1);
}
// All-In-One SEO
if (defined('AIOSEOP_VERSION'))
{
    global $aiosp;
    remove_action('wp_head',array($aiosp,'wp_head'));
}

I've tried running it within the function that calls the custom page, as well as the functions mp_custom_page_title and mp_custom_metatag_display, but no luck.

How can I disable these plugins on these pages? Any insight is greatly appreciated!

Share Improve this question asked Apr 29, 2020 at 21:35 DexterDexter 1076 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

For anyone that may be interested, I was able to solve this using the following code in mp_custom_page_title:

// JetPack
remove_action('wp_head','jetpack_og_tags');

// Yoast SEO
if (defined('WPSEO_VERSION'))
{
    global $wpseo_front;
    if (defined($wpseo_front))
    {
        remove_action('wp_head',array($wpseo_front,'head'),1);
    }
    else
    {
        $wp_thing = WPSEO_Frontend::get_instance();
        remove_action('wp_head',array($wp_thing,'head'),1);
    }
    add_filter('wpseo_opengraph_url','__return_false');
    add_filter('wpseo_opengraph_desc','__return_false');
    add_filter('wpseo_opengraph_title','__return_false');
    add_filter('wpseo_opengraph_type','__return_false');
    add_filter('wpseo_opengraph_site_name','__return_false');
    add_filter('wpseo_opengraph_image','__return_false');
    add_filter('wpseo_opengraph_author_facebook','__return_false');
    add_filter('Yoast\WP\Woocommerce\product_condition','__return_false');
}

// All-In-One SEO
if (defined('AIOSEOP_VERSION'))
{
    remove_action('wp_head',array($aiosp,'wp_head'));
}

remove_action('wp_head','rel_canonical');
remove_action('wp_head','index_rel_link');
remove_action('wp_head','start_post_rel_link');
remove_action('wp_head','adjacent_posts_rel_link_wp_head');

There are a list of useful Yoast functions here: https://gist.github/amboutwe/811e92b11e5277977047d44ea81ee9d4

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论