Please read About Title Tags in the Themes documentation before learning how to set them from a plugin.
Use the Hotaru object
The best place to set your title tags is from the hotaru_header hook.
Use isPage or keyExists to determine the page
If your query string contains a page argument, you can use that to set your title, e.g.
PHP Code:
if ($this->hotaru->isPage('myplugin')) {
$this->hotaru->title = "My Title";
}
Otherwise, the keyExists function in Inspekt enables you to check for url parameters that might determine what page you're on. Here are two real-life examples:
PHP Code:
if ($this->cage->get->keyExists('category')) {
and
PHP Code:
if ($this->cage->get->keyExists('tag')) {
The categories and tags plugins use those to determine if we're looking at a page of posts filtered to a specific category or tag.
Make your title readable
Once you know you're on the right page, you can simply set the title as follows:
PHP Code:
$hotaru->title = "My Title";
However, you'll most likely want to convert a value into a title, and to do that, Hotaru has some built-in formatting functions:
PHP Code:
$this->hotaru->pageToTitle('my_title');
will give you My title.
If you want to make all the words start with an uppercase letter, use:
PHP Code:
$this->hotaru->pageToTitleCaps('my_title');
which results in My Title.
So you might end up with something like:
PHP Code:
$this->hotaru->title = $hotaru->pageToTitleCaps('my_title'));
Bookmarks