I am trying to edit how a certain component I'm using on my site controls the title of the page.
Currently the component does not seem to control the title at all, and it's hard to get the developer to understand the importance of this and he's basically not helping me with this.
The component is huge, many files. It is for vehicle adverts. I have 2 PHP files that control the content of the vehicle details.
I have added this code at the beginning with all the document lines.
JFactory::getDocument()->setTitle('Set your title here');
This changes the title to the text "Set your title here" as it should.
My question is. Is there a way for me to change the text to be pulled automatically from information in that particular php file?
For example. Could I somehow make "Set your title here" be replaced with the info generated from this code?
<div id="jsautoz_detail_wraper">
<div class="detail_border">
<div class="js-row js-null-margin" id="auto_maintitle">
<div class="js-col-lg-9 js-col-md-9 js-col-sm-9 js-col-xs-12" id="auto_maintitle_text">
<?php echo JText::_($this->vehicle->maketitle) . ' ' . JText::_($this->vehicle->modeltitle) . '<span id="auto_model_year"> ( ' . $this->vehicle->modelyeartitle . ' )</span>'; ?>
</div>
This is the command that controls the title of the vehicle advert. I need that info to display ad the page <title>
</div>
Why don't you do something like:
$title = JText::_($this->vehicle->maketitle) . ' '
. Text::_($this->vehicle->modeltitle)
. '(' . $this->vehicle->modelyeartitle . ')';
JFactory::getDocument()->setTitle($title);
Turns out I managed to find a solution to this problem after weeks of searching, testing and asking questions.. and ofc it was not that hard.. but since my coding knowledge is really limited I would like to know if someone has any issue with this coding if it will be a problem for example with google searches etc.?
The code I created (with the help from the code from @user2914191 ) is:
$title= $this->vehicle->maketitle . ' ' . $this->vehicle->modeltitle . ' ' . $this->vehicle->modelyeartitle . ' ' . ('- Bílasíðan.is');
$document = JFactory::getDocument();
$document->setTitle($title);
Works like a charm when changing the title of the website. now it display's the vehicle make, vehicle mode, vehicle year and the name of the website. :D
However I am concerned by the Google search results. I guess I should let Google refresh for few days before I start being concerned but when I search for a specific vehicle title on google I get a couple that say "An error occurred." as the title. :/
</div>