COMMUNITY FORUM
k2 page titles configure
- Roman Lipatov
-
Topic Author
- Offline
- New Member
I need to create page title tags not same as item title.
So, if item title = item title, I need page title tag = my specific page title.
I think, I can do it using k2 extra fields.
But I can't find which file to edit — to set my page title tag = extra field with ID 1 (example).
Can you point me in right direction?
Thanks!
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
You need to override the item.php file.
This post will help you locate it: getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
Please Log in or Create an account to join the conversation.
- Roman Lipatov
-
Topic Author
- Offline
- New Member
But where in this file page title tag variable?
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Extrafields can be directly rendered in your template so you do not have to move the entire extrafields block.
Please Log in or Create an account to join the conversation.
- Roman Lipatov
-
Topic Author
- Offline
- New Member
I'm talking about meta tag Page title
I need to replace default meta tag <title> which is equal of k2 item title, on my own (for example k2 extra field)
Please Log in or Create an account to join the conversation.
- Kannan Naidu Venugopal
-
- Offline
- Platinum Member
- Aham Brahmasmi
To add custom page title based on your extra field value, try this
<?php
$newtitle= $this->item->extraFields->EXTRAFIELDALIASHERE->value;
$document = JFactory::getDocument();
$document->setTitle($newtitle);
?>
Simply replace EXTRAFIELDALIASHERE with the actual alias of the extra field you wish to output.
K2 Rocks \m/
Please Log in or Create an account to join the conversation.
- Roman Lipatov
-
Topic Author
- Offline
- New Member
Thanks!
It's works perfect :)
Please Log in or Create an account to join the conversation.
- Giorgio Basile
-
- Offline
- New Member
I would like to do the same but is not working for me.
I did override and pasted the code Kannan published with the correct Extra Fields alias in the item.php but now I have as Browser Page Title the page url and in the page code the meta name title has always the K2 article title.
Check this page : new.verticalife.it/index.php/it/viaggi-trekking-in-nepal/templi-e-vette-dell-himalaya
I've pasted it here :
<div class="itemHeader">
<?php
$newtitle= $this->item->extraFields->PageTitle->value;
$document = JFactory::getDocument();
$document->setTitle($newtitle);
?>
<?php if($this->item->params->get('itemDateCreated')): ?>
<!-- Date created -->
"PageTitle" is my Extra Fileds alias.
Can you please help me?
Many thanks!
Giorgio
Please Log in or Create an account to join the conversation.
- Kannan Naidu Venugopal
-
- Offline
- Platinum Member
- Aham Brahmasmi
Can you check if the extrafields is set to show in the configuration parameters?
K2 Rocks \m/
Please Log in or Create an account to join the conversation.
- Martin Richta
-
- Offline
- New Member
- Posts: 4
any idea how i can set up it?
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.
- 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
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
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
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
Please Log in or Create an account to join the conversation.