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

Question

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
, , Dexter 10 months 2020-04-29T17:10:40-05:00 0 Answers 85 views 0

Leave an answer