admin管理员组文章数量:1516870
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 badges1 Answer
Reset to default 0For 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
本文标签:
版权声明:本文标题:url rewriting - Disabling Yoast, All-in-One, and Rank Math on Certain Pages within a Plugin 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.betaflare.com/web/1744486170a2608462.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论