I'm coding a plugin that allows me to dynamically insert content for my meta description and title. The content is already being pulled fine, the only part I can't get to work is actually filtering the meta description.

I was able to get the title working like this:

add_filter( 'wp_title', 'filter_wp_title');
function filter_wp_title( $title ){
    $title = wpg_modules($title);
    return( $title );

where wpg_modules() returns the content to use for the title. But I can't find an equivalent way to do this for the meta description, presumably because WP doesn't just always have one unless your theme or another plugin does.

Please note the above code works perfectly and is not what I need help with, I merely provided it as an example of filtering the title that works fine.

So, how can I filter an existing meta description, if present?

1 Answer 1


Looks like a syntax error.

Change this:

return( $title );

to this:

return $title;


Sorry; mis-read your question.

I believe the question is entirely Theme-dependent. The description normally is output in the template via bloginfo( 'description' ). The bloginfo() function uses get_bloginfo(), which uses a simple switch, and for the description parameter, the function simply returns get_option( 'blogdescription' ).

So, I'm not seeing any filters being applied anywhere in that process.

Have you taken a look at what any of the myriad SEO Plugins do with respect to the description meta tag?


Any ideas?

Short of writing a core patch, to add a wp_description() wrapper function, complete with apply_filters() call, around get_bloginfo( 'description' )? Not really...

  • No, that part works fine, either approach works. But that's not the issue. If you could re-read what I need (to filter the meta description) and offer any additional suggestions I'd greatly appreciate it!
    – Jonathan
    Jul 10, 2011 at 3:29
  • Thanks for the followup! I could edit the theme, yes... but then it would work ONLY in that specific theme which is not desirable. I need a way to do this via a filter so that it will be theme agnostic. I have looked at many SEO plugins, and they all can easily ADD meta tags, but I want to MODIFY existing ones, which appears to be a completely different animal. If I could get the_head just like you can with the_content, then it would be theoretically fairly simple. But there appears to be no way to get the <head> contents, and filter them in place. Any other ideas??
    – Jonathan
    Jul 10, 2011 at 3:36
  • yeah I was hoping to not have to get quite so "hard core" with this. Thought it would be as simple as filtering the_meta but now that I've played with all sorts of approaches, it's clear why none of them can work. I could also filter the content of a specific seo plugin, but then again this would only work on blogs that have that specific plugin installed, which I'd like to avoid. So much more difficult than I thought it would be. If you have any flashes of inspiration, please let me know! =)
    – Jonathan
    Jul 10, 2011 at 3:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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