Keyword

Meta title (continue)

More
5 years 10 months ago #168208 by lalancuras
Replied by lalancuras on 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.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
5 years 10 months ago #168222 by Krikor Boghossian
Replied by Krikor Boghossian on 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?

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

More
5 years 9 months ago #168343 by lalancuras
Replied by lalancuras on 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.


Powered by Kunena Forum