Ale*_*kel 3 wordpress wordpress-hook
我不希望 TAG 页面显示在我的 WordPress 中,并且我想要重定向到主页而不是 noindex。
我无法使用 NGINX 重定向,因为我的 Wordpress 在多语言中“标签”一词是可翻译的,它可以更改(而且我真的不想让它碰运气,在一年中,当我们添加另一种语言时,我会忘记添加这个重定向)
目前我正在使用这个:
public function my_template_include($original_template)
{
global $wp_query;
// we dont use tags...
if(is_tag()){
wp_redirect('/',301);
exit();
}
}
add_filter('template_include', array($this, 'my_template_include'), 10, 1);
Run Code Online (Sandbox Code Playgroud)
但我很确定应该有比这更好的方法。
PS我已经使用: unregister_taxonomy_for_object_type 但是,它删除了添加标签的选项,但不会删除系统中当前现有的标签,也不会删除它创建的页面!
我相信您想使用内置的 WP 过滤器register_taxonomy_args
,它允许您过滤/调整所有分类法,包括内置的“标签”分类法。您可以使用过滤器禁用该public
设置,这应该将其从 WP 的前端删除。(如果public
没有具体执行您想要的操作,请阅读register_taxonomy args,并根据需要进行调整/测试)。
add_filter( 'register_taxonomy_args', 'my_tags_disable', 10, 3 );
function my_tags_disable( $args, $name, $object_type ) {
// if it's no the "tag" taxonomy, don't make changes
if ( 'post_tag' !== $name ) {
return $args;
}
// override the specific arguments to remove the archive from the front-end
$args['public'] = FALSE;
$args['publicly_queryable'] = FALSE;
// return the modified arguments
return $args;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4478 次 |
最近记录: |