- Posts: 15920
COMMUNITY FORUM
k2 page titles configure
- Krikor Boghossian
-
- Offline
- Platinum Member
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- burnyourears
-
- Offline
- Senior Member
- Posts: 66
I use this code to place the article-title and the category in the page title. So far it's working:
<?php
$newtitle= (' Review: ' . $this->item->title . ' | ' . $this->item->category->name);
$document = JFactory::getDocument();
$document->setTitle($newtitle);
?>
My problem: When an article has the special character >> ' << , it shows the html-code in the page title instead: #039;
> For example, "Spock's Beard" is getting "Spock#039;s Beard" in the page title.
Any idea how I could fix that?
:-)
Please Log in or Create an account to join the conversation.
- Ronny Van Der Borght
-
- Offline
- Senior Member
$safe = array("", "");
$nonsafe = array("'", "\"");
$custometa = $this->item->title;
$safemeta = str_replace( $nonsafe, $safe, $custometa);
echo $safemeta;
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- burnyourears
-
- Offline
- Senior Member
- Posts: 66
Unfortunately I am no coder and need some help how to integrate this within my code ... Where do I have to put the " $safemeta;" ? Something like this (does not work ...) ?
<?php
$safe = array("", "");
$nonsafe = array("'", "\"");
$custometa = $this->item->title;
$safemeta = str_replace( $nonsafe, $safe, $custometa);
$newtitle= (' Review: ' . $safemeta . ' | ' . $this->item->category->name);
$document = JFactory::getDocument();
$document->setTitle($newtitle);
?>
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Make sure to always use overrides :) getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- burnyourears
-
- Offline
- Senior Member
- Posts: 66
But I don‘t know where in the code and how to merge with my codesnippet. Hmmm...
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- burnyourears
-
- Offline
- Senior Member
- Posts: 66
<?php
$safe = array("", "");
$nonsafe = array("'", "\"");
$custometa = (' Review: ' . $this->item->title . ' | ' . $this->item->category->name);
$newtitle= str_replace( $nonsafe, $safe, $custometa);
$document = JFactory::getDocument();
$document->setTitle($newtitle);
?>
But the ' still is in the title tag. What do I not understand?
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- burnyourears
-
- Offline
- Senior Member
- Posts: 66
<?php
$newtitle= ($this->item->title . ' | Review');
$document = JFactory::getDocument();
$document->setTitle($newtitle);
?>
When I delete that part of the code, everything is fine and "Spock's Beard" looks fine as it should. So it must have something to do with the posted snippet ...
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
$safe = array("", "");
$nonsafe = array("'", "\"");
$safemeta = str_replace( $nonsafe, $safe, $this->item->title);
$newtitle = (' Review: ' . $safemeta . ' | ' . $this->item->category->name);
$document = JFactory::getDocument();
$document->setTitle($newtitle);
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- burnyourears
-
- Offline
- Senior Member
- Posts: 66
That's the code I use:
<?php
$safe = array("", "");
$nonsafe = array("'", "\"");
$safemeta = str_replace( $nonsafe, $safe, $this->item->title);
$newtitle = ($safemeta . ' | Review - XXX');
$document = JFactory::getDocument();
$document->setTitle($newtitle);
?>
Any further idea? :/
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
<?php
$safe = array("", "", "", "");
$nonsafe = array("'", "\"", "", "#039;", "&");
$safemeta = str_replace( $nonsafe, $safe, $this->item->title);
echo $safemeta;
?>
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- burnyourears
-
- Offline
- Senior Member
- Posts: 66
One last idea?
That's the code right now:
<?php
$safe = array("", "", "", "");
$nonsafe = array("'", "\"", "", "#039;", "&");
$safemeta = str_replace( $nonsafe, $safe, $this->item->title);
$newtitle = ($safemeta . ' | Review - XXX');
$document = JFactory::getDocument();
$document->setTitle($newtitle);
?>
Please Log in or Create an account to join the conversation.
- burnyourears
-
- Offline
- Senior Member
- Posts: 66
<?php
$safe = array("'");
$nonsafe = array("'");
$safemeta = str_replace( $nonsafe, $safe, $this->item->title);
$newtitle = ($safemeta . ' | Review - XXX');
$document = JFactory::getDocument();
$document->setTitle($newtitle);
?>
So your ideas lead to that point I could make it – thank you very much! :D
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Wilfried
-
- Offline
- Junior Member
- Posts: 22
<?php
$newtitle= $this->item->extraFields->EXTRAFIELDALIASHERE->value;
$document = JFactory::getDocument();
$document->setTitle($newtitle);
?>
I used this solution to add the tag <title> to each page of my website. The result is ok, but the extrafield is visible in frontend. Is it possible to hide the extrafield in the frontend and only have the option in the backend?
Example: the word "Test" appear in the navigator and the extrafield "Balise title:" is visible before the video.
www.cryptoseries.fr/series/item/445-huff
Sorry for my english, I am french.
Please Log in or Create an account to join the conversation.
- Wilfried
-
- Offline
- Junior Member
- Posts: 22
Thanks
Please Log in or Create an account to join the conversation.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.