0

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 Mar 8 '17 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 Mar 8 '17 at 23:21
0

If you want to remote <meta name="description" content="" /> in html head, Add

remove_action('wp_head', 'description');

into your function.php.

| improve this answer | |
  • I only want to remove it on one of the pages, not all of them. Also, is there a way to change the description too if need be? – Josh Holly Mar 10 '17 at 3:40
  • One way of doing what you want is to create a specific page.php template for the page and run the remove_action on the page after wp_head();. On your second question, I actually use a plugin (i decided too much trouble to write my own code) called easy-wp-meta-description which allows me to create the meta description content on each post for better SEO score. – hcheung Mar 10 '17 at 5:54
  • Sorry, it should be get_header();, not wp_head();. – hcheung Mar 10 '17 at 7:03
  • I did the remove_action function on the page after get_header() and it didn't change anything. Also, I have TONS of posts, so that would take FOREVER to do. Insteead, I wrote a code that generated a meta description tag. It's working fine, just got to get rid of the old meta description tag cause it's confusing google. – Josh Holly Mar 11 '17 at 6:28
0

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 ?>
| improve this answer | |
  • That's what I'm doing right now. However, all that does is add another meta tag, not change the current one. – Josh Holly Mar 11 '17 at 6:25
0

You 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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.