when is the_title() set?
-
I am writing a plugin that needs to only run on one page of the blog. I don’t know if there’s a canonical way to do this, but I tried doing it by getting the name of the current page from the built-in function “the_title()”
Let’s say I have a WordPress page named “test” and the permalink for it is also “test” (so I would expect the_title() to return the string “test”)
I have a file in my plugins directory: plugins/my_plugin/my_plugin.php
And the contents of this file are:
<?php /* Plugin Name: my_plugin */ if (the_title()=="test") { ... do stuff... } ?>
but this doesn’t work, and adding an “else” clause like:
else { $the_title=the_title() echo "THE TITLE IS '$the_title'"; }
reveals that the_title() is returning the empty string. Other functions like “the_permalink()” also return the empty string.
Why don’t these functions work? Or, what is a better way to make my plugin run on only one page?
Thank you.
- The topic ‘when is the_title() set?’ is closed to new replies.