I have search a lot but cannot find any solution for my problem.

I when i entered the search term to the search box of my website, it goes to mysite.com/search/search+term. However, the result page does not have meta keywords and meta description. I trying to find way to add these values into the header of the result page with meta keywords = search term and meta description = information about the search term.

I think i will need to modify the search.php or query.php files, but not sure how to do. I don't want to change the header.php because it will conflict with other normal posts.

Anyone has any suggestion how to do this?

Thank you in advance!

2 Answers 2


that is relatively easy. you can add this to your theme's functions.php file

add_action('wp_head', 'add_meta_tags');
function add_meta_tags(){

    $search_keyword = get_search_query();
    echo '<meta name="META_NAME" content="META TESTING" />';

you may change echo '<meta name="META_NAME" content="META TESTING" />'; as you want to output the meta tags.

however, your theme needs to call wp_head(); for this to work. check your theme's header.php file.

  • Thank you very much, HungryCoder! It works almost perfectly. The only problem exists is the outcome is 2 meta value being continuous in a line, something like this <meta name="keyword" content="keyword"><meta name="description" content="description>. Is there any way to separate the 2 meta value in two line separately? Since i'm not sure if it affect SEO
    – Pam Apple
    Jun 18, 2012 at 15:57
  • That's very easy. echo '<meta name="META_NAME" content="META TESTING" />'.PHP_EOL;. however, both in same line is not a problem. Jun 18, 2012 at 16:43

Your specific solution depends on how your header.php file currently implements those two meta tags (static, filtered, etc.).

The simplest solution is to edit your header.php file but wrap your changes in the is_search() function:

<?php if ( is_search() ) : ?> . . . <?php else: ?> . . . <?php endif; ?>

The more graceful (/complicated) solution would be to filter the output with a custom filter.

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.