WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

does WP offer any functions which can be used to set the page title and/or keywords from the PHP/Controller level?

I'm basically looking for something like the wp_enqueue_style() function, which results in changes to the HTML page header but for the title and keywords fields. I have some PHP code which dynamically retrieves/builds the page title and would like to avoid having to alter my theme/templates to display this.

Greetings/Thanks Robert

share|improve this question
up vote 2 down vote accepted

You can use the wp_title filter to modify the HTML document title, and you can use the wp_head action to hook in a custom HTML meta link. e.g.:

function wpse46249_filter_wp_title( $title ) {
    // $title contains the default document title
    // output by WordPress. Modify it here however
    // you want.
    $some_custom_title_content = 'CUSTOM TITLE CONTENT HERE';
    // Now append it to the default
    $custom_title = $title . $some_custom_title_content;
    // Then return the result
    return $custom_title;
add_filter( 'wp_title', 'wpse46249_filter_wp_title' );

function wpse46249_add_meta_link() {
    echo '<meta name="keywords" content="INSERT KEYWORDS HERE" />';
add_action( 'wp_head', 'wpse46249_add_meta_link' );

These callbacks can be added to a Plugin, to keep them safe from Theme switching.

For further reference, I would recommend taking a look at how the popular SEO Plugins implement these extensions.

share|improve this answer
@user13955 Here's links to the filter and action hooks references from WordPress for more of a foundation on Chip's answer. – Brent Mar 20 '12 at 20:16
Thank you very much, I'll give this a try tomorrow morning. This seems to be exactly what I was looking for! – user13955 Mar 20 '12 at 21:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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