Keyword

Meta title (continue)

More
4 months 1 week ago #168208 by lalancuras
lalancuras replied the topic: Meta title (continue)
<?php
  // Use extrafields as meta data - thank you @heyjoecampbell and @kbrookes
$doc = JFactory::getDocument();
if ( isset( $this->item->extraFields->setTitle->value ) && ($this->item->extraFields->setTitle->value !=='') ) {
	$doc->addCustomTag('<title>'.$this->item->extraFields->setTitle->value.'</title>');
}
if ( isset( $this->item->extraFields->setMetaData->value ) && ($this->item->extraFields->setMetaData->value !=='') ) {
	$doc->addCustomTag('<meta name="description" content="'.$this->item->extraFields->setMetaData->value.'" />');
}
// See also https://gist.github.com/kricore/2c9a5434748c5f5f6cf9
// Cleanup the extrafields content so you can use them as metatags
$safe 		= array("", "");
$nonsafe 	= array("'", "\"");
$custometa  = $this->item->extraFields->newtitle->value;
$safemeta 	= str_replace( $nonsafe, $safe, $custometa);
echo $safemeta;
?>

maybe i don't understarnd, i try this but not sucess

Please Log in or Create an account to join the conversation.

More
4 months 1 week ago #168222 by Krikor Boghossian
Krikor Boghossian replied the topic: Meta title (continue)
This part is not required
It is there as a helper function if you need to clean up the metas before adding them as tags.
// See also https://gist.github.com/kricore/2c9a5434748c5f5f6cf9
// Cleanup the extrafields content so you can use them as metatags
$safe 		= array("", "");
$nonsafe 	= array("'", "\"");
$custometa  = $this->item->extraFields->newtitle->value;
$safemeta 	= str_replace( $nonsafe, $safe, $custometa);
echo $safemeta;

In my last post, I mentioned two methods from Joomla!'s API instead of addCustomTag (check the links).
Can you try these methods instead?

IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

---
JoomlaWorks
www.joomlaworks.net/

Please Log in or Create an account to join the conversation.

More
3 months 3 weeks ago #168343 by lalancuras
lalancuras replied the topic: Meta title (continue)
I just paste

"setTitle(string $title) : \Joomla\CMS\Document\Document"

in item.php ?

thx for you re help

Please Log in or Create an account to join the conversation.

Moderators: william white