- Posts: 24
COMMUNITY FORUM
Meta title (continue)
- Mauri
-
Topic Author
- Offline
- Junior Member
When I enter in other topic I´m able to reply, not in mine, I don´t understand
Y copy paste the post and after the replies:
Hi all! I have a little problem with K2 and Meta Title tag, I change it in the menu item but im not able to change the <title> tag it only changes
meta property="go:title"
How can I change meta title in categories or any article?
Thanks in advance
Krikor was telling about my website, here you have:
www.eventosbarcelona.cat/danza
If you see, here are two meta titles, I change in menu item - Browser window display it only changes the meta property="go:title" tag, not the main title tag, how can I do it?
Thanks in advance!! :-)
Mauri
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
The og:title is automatically generated from K2. It inherits the category's or the item's title.
This is the default behaviour I would urge not to hack core K2 files.
You can add your own custom meta tags using Joomla!'s API docs.joomla.org/JDocument/setMetaData
docs.joomla.org/Customising_the_dynamic_page_title
You can find a crude example which works with K2's extrafields which you can adapt to replace the og:tag and work with Joomla!'s title here -> github.com/kricore/Advanced-templating-with-K2/blob/master/_inc/cheatsheet.php#L112-L115
Please Log in or Create an account to join the conversation.
- Ronny Van Der Borght
-
- Offline
- Senior Member
$browserpagetitle= $this->item->extraFields->custompagetitle->value;
$document = JFactory::getDocument();
$document->setTitle($browserpagetitle);
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
github.com/kricore/Advanced-templating-with-K2/blob/master/_inc/cheatsheet.php
Please Log in or Create an account to join the conversation.
- lalancuras
-
- Offline
- New Member
- Posts: 9
i add :
// Use extrafields as meta data - thank you @heyjoecampbell and @kbrookes
$doc = JFactory::getDocument();
if ( isset( $this->item->extraFields->title_tag->value ) && ($this->item->extraFields->title_tag->value !=='') ) {
$doc->addCustomTag('<title>'.$this->item->extraFields->title_tag->value.'</title>');
}
if ( isset( $this->item->extraFields->meta_description->value ) && ($this->item->extraFields->meta_description->value !=='') ) {
$doc->addCustomTag('<meta name="description" content="'.$this->item->extraFields->meta_description->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->NAME->value;
$safemeta = str_replace( $nonsafe, $safe, $custometa);
echo $safemeta;
on itemp.php (in my template)
I create extrafield
but don't work. I don't know where is my mistake
maybe be here : $custometa = $this->item->extraFields->NAME->value;
?
link page test : www.comportementaliste-gironde.fr/blog-education-canine/476-comment-bien-dresser-son-chien.html
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Please Log in or Create an account to join the conversation.
- lalancuras
-
- Offline
- New Member
- Posts: 9
Informations supplémentaires
Balise title: Apprendre à bien dresser son chien
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Please Log in or Create an account to join the conversation.
- lalancuras
-
- Offline
- New Member
- Posts: 9
i try to disable but don"t work :(
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Please Log in or Create an account to join the conversation.
- lalancuras
-
- Offline
- New Member
- Posts: 9
<?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
-
- Offline
- Platinum Member
- Posts: 15920
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?
Please Log in or Create an account to join the conversation.
- lalancuras
-
- Offline
- New Member
- Posts: 9
"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.