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

Is it possible to change the page title with code?

For example, let's say the page's name is "Book your Order", but I want to change it to "Book Order #123".

I Google'd a bit and looked here and didn't see anything. Anyone know of a plugin or hack?

wp_title returns the page title but doesn't allow setting the page title: http://codex.wordpress.org/Function_Reference/wp_title

share|improve this question
Where would the value come from? what has in that page the value of #123 ? – Sagive SEO Nov 7 '11 at 18:51
up vote 12 down vote accepted

There is no documentation on it but you could always apply a filter to the_title like this:

function some_callback($data){
    global $post;
    // where $data would be string(#) "current title"
    // Example:
    // (you would want to change $post->ID to however you are getting the book order #,
    // but you can see how it works this way with global $post;)
    return 'Book Order #' . $post->ID;

See these:



share|improve this answer
This is great, thank you. – Alex Cook Jan 16 '12 at 19:35

So you want to change the title on a per page basis? Firstly setup a custom post met a box. Smashing Magazine covered this recently: http://wp.smashingmagazine.com/2011/10/04/create-custom-post-meta-boxes-wordpress/. You can then create a simple function to replace the title if the custom meta box has a value.

There are several SEO plugins that also provide this functionality. Try Yoast SEO for examples: http://wordpress.org/extend/plugins/wordpress-seo/

Hope this helps.

share|improve this answer
These solutions wont change the title "dynamically" but "manually". – Gustavo Aug 29 '15 at 23:31

Really depends if you're looking to display a custom title for the current page (i.e. the contents of the <title></title> tag in the header) or filter the title of pages in the page body or in listings.

In the former case (the title of the current page), try adding a filter for wp_title() like so: http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_title

If you want to modify page titles across the board, filtering the_title() will do the trick: http://codex.wordpress.org/Plugin_API/Filter_Reference/the_title

share|improve this answer
Actually in my experience you need to filter both wp_title and the_title to cover both. – Geoffrey Mar 26 '15 at 8:59

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.