我试图在一个页面上禁用Wordpress Yoast SEO,因为它与另一个插件冲突.
我尝试了这个StackOverflow问题,将此代码添加到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
}
}
Run Code Online (Sandbox Code Playgroud)
上面没有用,所以我然后跑过这个帖子,并尝试将其改为下面,这当然导致500错误.
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
}
}
Run Code Online (Sandbox Code Playgroud)
关于如何在一个页面上禁用Yoast SEO的任何想法?我应该从functions.php或其他地方这样做吗?我想我很接近,但不是很接近.
好的,我弄清楚我做错了什么.以下是正在运行的更正代码:
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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
| 归档时间: |
|
| 查看次数: |
3429 次 |
| 最近记录: |