admin管理员组文章数量:1122846
Wordpress renders a meta description tag with the content of the blog post as the value for the description.
I already generated in the header.php
what I want the description to be, no matter what. However, the old one is still in there. I checked single-post.php
and header.php
and there is nothing rendering the meta description. So it HAS to be the wp_head()
function.
Is there anyway I can put something in my functions.php
or something to ensure that on certain pages the meta description is removed from wp_head()
?
Wordpress renders a meta description tag with the content of the blog post as the value for the description.
I already generated in the header.php
what I want the description to be, no matter what. However, the old one is still in there. I checked single-post.php
and header.php
and there is nothing rendering the meta description. So it HAS to be the wp_head()
function.
Is there anyway I can put something in my functions.php
or something to ensure that on certain pages the meta description is removed from wp_head()
?
- Have you tried switching themes to make certain it isn't your theme, and have you tried disabling all your plugins to see if any of them are setting it? single-post.php and header.php are not the only places in a theme one could set a meta description, and the theme is not the only option either. – WebElaine Commented Mar 8, 2017 at 22:38
- It's not the theme, seeing that I have the same theme on my test site and it doesn't do that. I literally have no clue where the meta tag is coming from. I don't want to disable all the plugins on my main site as it is a large website that I hate to see go down. – Josh Holly Commented Mar 8, 2017 at 23:21
3 Answers
Reset to default 1You should be able to remove the existing description tag with the following code:
remove_action( 'wp_head', '_wp_render_title_tag', 1 );
Put the above snippet inside the same function you are using to conditionally add a new tag so there is always only a single description tag at a time.
If you want to remote <meta name="description" content="" />
in html head, Add
remove_action('wp_head', 'description');
into your function.php.
For change the content of the meta description:
<?php
$description = '';
if( is_single() or is_page() ){
global $post;
$description = get_post_meta( $post->ID, $this->meta_key, true );
} ?>
<?php if( $description ): ?>
<meta name="description" content="<?php print $description; ?>"
<?php endif ?>
本文标签: phpRemove meta description on certain pages
版权声明:本文标题:php - Remove meta description on certain pages 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736298072a1930149.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论