Title: wp_title &#8211;&gt; var
Last modified: August 20, 2016

---

# wp_title –> var

 *  Resolved [t567](https://wordpress.org/support/users/t567/)
 * (@t567)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/wp_title-var/)
 * hi @ all,
 * i’m trying to get wp_title as a string in order to use it in a if statement, 
   hence i want to display content only if the string has a certain value (page 
   title). i put the following into the top level index.php:
 *     ```
       <?php $var = wp_title('',false);  // putting wp_title into string
       echo "$var";  // just a test - works, prints the title of the page
       if($var == "PAGE TITLE") // no more than a simple if statement...
       {
        echo "lorem ipsum"; // no output :(
       ?>
       ```
   
 * i’m not using any theme but inserted wp into an existing website.
 * any hints?
 * regards t567

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

 *  [michael.mariart](https://wordpress.org/support/users/michaelmariart/)
 * (@michaelmariart)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/wp_title-var/#post-3001270)
 * Is $var actually “PAGE TITLE”? To do that sort of comparison, the two strings
   must be exactly the same. If $var is ‘Page Title” it won’t work (different capitalisation),
   or if there’s two spaces, or any one of a lot of other things.
 * There’s other PHP functions that might be more useful, like strcmp () so have
   a look at a few options and see what works for you.
 *  Thread Starter [t567](https://wordpress.org/support/users/t567/)
 * (@t567)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/wp_title-var/#post-3001291)
 * hi michael,
 * thnx for your reply.
 * >Is $var actually “PAGE TITLE”?
 * no, i guess i didn’t put it clear enough, i’m trying to use wp_title as a variable.
   so if wp_title i.e. is “Mustang”, hence the related page is about mustangs and
   called accordingly, i want to use the variable “Mustang” in the if statement 
   in order to display some extra content only related to the page about mustangs.
 * the above script works fine as it is but it does not when inserted in the index.
   php.
 *  [michael.mariart](https://wordpress.org/support/users/michaelmariart/)
 * (@michaelmariart)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/wp_title-var/#post-3001293)
 * OK, either way the actual string that is is doesn’t really matter, as the yshould
   match if they are the same.
 * Try changing the comparison function to strcmp() and see waht that outputs. That’s
   really all that I can think of to do.
 *  Thread Starter [t567](https://wordpress.org/support/users/t567/)
 * (@t567)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/wp_title-var/#post-3001294)
 * ok, i’ll give it a try…
 *  Thread Starter [t567](https://wordpress.org/support/users/t567/)
 * (@t567)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/wp_title-var/#post-3001298)
 * hm, no, doesn’t do anything else. the strcmp() works fine on a test-file but 
   doesn’t on the index.php.
 *     ```
       <?php $var = wp_title('',false);
       echo "$var";  // just a test, works
       if (strcmp("$var","Mustang") == 0)
       {
       echo "bananas are somewhat smaller than mustangs.";
       }
       ?>
       ```
   
 * maybe i shouldn’t mess around to much with wp, hence there is some more to it
   than bananas and mustangs 😉
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/wp_title-var/#post-3001383)
 * `wp_title()` seems to return the string with (two) prepended space characters;
 * try to use:
 * `if(trim($var) == "PAGE TITLE")`
 * [http://php.net/manual/en/function.trim.php](http://php.net/manual/en/function.trim.php)
 *  Thread Starter [t567](https://wordpress.org/support/users/t567/)
 * (@t567)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/wp_title-var/#post-3001393)
 * >wp_title() seems to return the string with (two) prepended space characters;
 * obviously it does. your hint immediately did solve the problem. thanx a lot!

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

The topic ‘wp_title –> var’ is closed to new replies.

 * 7 replies
 * 3 participants
 * Last reply from: [t567](https://wordpress.org/support/users/t567/)
 * Last activity: [13 years, 7 months ago](https://wordpress.org/support/topic/wp_title-var/#post-3001393)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
