Title: Dynamically changing the page title?
Last modified: August 20, 2016

---

# Dynamically changing the page title?

 *  [nexusmedia](https://wordpress.org/support/users/nexusmedia/)
 * (@nexusmedia)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/dynamically-changing-the-page-title/)
 * How do I dynamically set the page title? I would like to specify the page title
   before wp_head is passed, so that the <title> tag will output whatever I want.
   I’ve searched for a while but can’t find a simple solution.
 * I don’t want to display or return wp_title – I want to dynamically SET it before
   it’s output to the page from within a custom content type, ie.
 * set_wpl_title(‘My Custom Title’);
 * And when wp_head is called, all the other stuff is included plus
 * <title>My Custom Title</title>
 * Any simple way of achieving this?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [mnolf](https://wordpress.org/support/users/mnolf/)
 * (@mnolf)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/dynamically-changing-the-page-title/#post-2295108)
 * i’d like to do exactly the same thing.
    did you have any luck so far?
 *  Thread Starter [nexusmedia](https://wordpress.org/support/users/nexusmedia/)
 * (@nexusmedia)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/dynamically-changing-the-page-title/#post-2295109)
 * Not really, but I created a bit of a hack to achieve what I was trying to accomplish:
 * So wherever I wanted the customize the page title, I would set a global variable
   containing the required title and then call get_header():
 *     ```
       global $title;
       $title = 'My Custom Title';
       get_header(); ?>
       ```
   
 * And then the header.php page looks like this:
 *     ```
       <? global $title; ?>
       <? if ($title): ?>
       <title><?=$title?></title>
       <? else: ?>
       <title>
       <? wp_title('');?>
       </title>
       <? endif; ?>
       ```
   
 * This could be shorthanded with a ternary syntax:
 *     ```
       <? global $title; ?>
       <? ($title) ? $title : wp_title('') ;?>
       ```
   
 * So not the cleanest solution, but it got the job done.
 *  [mnolf](https://wordpress.org/support/users/mnolf/)
 * (@mnolf)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/dynamically-changing-the-page-title/#post-2295111)
 * for some reason, the short version doesn’t work for me. the long one, however,
   works perfectly.
    thanks very much!
 * (side note: when using the “all in one SEO” plugin, it needs to be deactivated
   on the concerned pages)

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Dynamically changing the page title?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [mnolf](https://wordpress.org/support/users/mnolf/)
 * Last activity: [14 years, 6 months ago](https://wordpress.org/support/topic/dynamically-changing-the-page-title/#post-2295111)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
