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!

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.com/amboutwe/811e92b11e5277977047d44ea81ee9d4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.