Hi
Do I just use this code in my custom file?
Yes.
One thing I don't understand though, how do I only execute this code in a certain file where I want the override to happen?
This is not about a file but you have to decid based on the requested URL.
There are 2 basic ways to do that:
1 - the $pageInfo variable that's provided to you has a field that gives you the current SEF and the current non-SEF URL . So you can do something like this, based on the current SEF url:
ShlHook::add(
'sh404sef_meta_page_title',
function ($title, $pageInfo) {
$title .= ' modified with filter';
if(wbEndsWith($pageInfo->currentSefUrl, '/apples')) {
$title = 'Some specific title';
}
return $title;
}
);
2 - An alternative is to use the Joomla input API:
ShlHook::add(
'sh404sef_meta_page_title',
function ($title, $pageInfo) {
$title .= ' modified with filter';
$input = JFactory::getApplication()->input;
if (
$input->getCmd('option') == 'com_content'
&&
$input->getCmd('view') == 'article'
&&
$input->getInt('id') > 20
&&
$input->getInt('id') < 30
)
{
$title = 'Some specific title';
}
return $title;
}
);
In this example, you check that the component on the current page is com_content (ie an article or a category), that we are on a "view=article" page and if the "id" is between 20 and 30, then we change the title.
That's just to get you an idea, you'd need to adjust the criteria to change the title and how you change the title to your needs.
[EDIT] In both these examples, the title will always be modified by appending to it ' modified with filter'. Then depending on the condition checked, the title may be replaced entirely by 'Some specific title' (the first part does $title
.= 'modified with filter' which adds to the title, while the second part does $title
= 'Some specific title' which replaces the title with a new value.
Best regards
Yannick Gaultier
weeblr.com
@weeblr