在单页上禁用 Wordpress Yoast SEO [英] Disable Wordpress Yoast SEO on Single Page
问题描述
我试图在单个页面上禁用 Wordpress Yoast SEO,因为它与其他插件冲突.
I'm attempting to disable the Wordpress Yoast SEO on a single page because it's conflicting with a different plugin.
我尝试按照这个 StackOverflow 问题,将此代码添加到functions.php:
I tried following this StackOverflow question, adding this code to functions.php:
add_action('template_redirect','remove_wpseo');
function remove_wpseo(){
if ( is_page(944)) {
global $wpseo_front;
remove_action( 'wp_head', array($wpseo_front, 'head'), 2 ); // <-- check priority
}
}
上述方法不起作用,所以我遇到了 这篇文章,并试图将其更改为以下,这当然导致了 500 错误.
The above did not work, so I then ran across this post, and tried to change it to below, which of course resulted in a 500 error.
add_action('template_redirect','remove_wpseo');
function remove_wpseo(){
if ( is_page(5526)) {
global WPSEO_Frontend::get_instance()
remove_action( 'wp_head', array(WPSEO_Frontend::get_instance(), 'head'), 2 ); // <-- check priority
}
}
关于如何在单个页面上禁用 Yoast SEO 的任何想法?我应该从 functions.php 或其他地方执行此操作吗?我想我已经接近了,但还没有完全到位.
Any ideas on how I might go about disabling Yoast SEO on a single page? Should I do this from functions.php or somewhere else? I think I'm close, but not quite there.
推荐答案
好的,我知道我做错了什么.这是正在工作的更正代码:
Okay, I figured out what I was doing wrong. Here is the corrected code which is working:
add_action('template_redirect','remove_wpseo');
function remove_wpseo(){
if (is_page(5526)) {
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);
}
}
}
谢谢!
这篇关于在单页上禁用 Wordpress Yoast SEO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!