Some Meta title trickery... help please?

Permalink
Hi Ok, if you can help me with this it would be great...

As standard the Page Title is:

<title>Sitename :: Pagename</title>


by adding the following to the config.php file:

define('PAGE_TITLE_FORMAT', '%2$s | %1$s');


I can get:

<title>Pagename | Sitename</title>


But now I want to add a metatitle, which is great as it replaces the Pagename, but it also replaces the Sitename by default so you just get:

<title>Metatitle</title>


Anyone know how I get it to read:

<title>Metatitle | Sitename</title>


The main reason for this is I then want to pull the Metatitle for use as the Pagename if its avaliable:

<h1><?php
   $metaTitle = $c->getCollectionAttributeValue('meta_title');
   if(!empty($metaTitle)) {
      print $metaTitle;
   } else {
      print $c->getCollectionName(); 
   }
?></h1>


Is there a better way of doing this? Thanks!

BHWW
 
bryanlewis replied on at Permalink Reply
bryanlewis
In C5 if you navigate to the page you want to change the title too.

1. Edit page.
2. Click on Properties
3. Click on the Custom Attributes Tab
4. Edit Meta Title to your liking
5. Click Save
6. Click Exit Edit Mode
7. Publish
BHWW replied on at Permalink Reply
BHWW
Thanks Bryan, yep that makes sense, I think its gonna be a bit trickier than that though, as say I put "High End Carrot Sales" as the Metatitle, the Page title then becomes "High End Carrot Sales" not "High End Carrot Sales | The Top Notch Veg Patch Shop".

Hi Anybody know how to solve this? I could really do with a solution.

Thanks, Ben
BHWW replied on at Permalink Reply
BHWW
Ok, for anyone who's reading this later, I actually worked this out now, what you need to do is: copy the file header_required.php from /concrete/elements/header_required.php to /elements/header_required.php.

Then change lines 25 - 31 from:

if ($akt) { 
   $pageTitle = $akt; 
   ?><title><?php echo htmlspecialchars($akt, ENT_COMPAT, APP_CHARSET)?></title>
<?php  } else { 
   $pageTitle = htmlspecialchars($c->getCollectionName(), ENT_COMPAT, APP_CHARSET);
   ?><title><?php echo sprintf(PAGE_TITLE_FORMAT, SITE, $pageTitle)?></title>
<?php  }


to:

if ($akt) { 
$pageTitle = htmlspecialchars($akt, ENT_COMPAT, APP_CHARSET); 
?> <title><?php echo sprintf(PAGE_TITLE_FORMAT, SITE, $pageTitle)?></title>
<?php } else { 
$pageTitle = htmlspecialchars($c->getCollectionName(), ENT_COMPAT, APP_CHARSET);
?> <title><?php echo sprintf(PAGE_TITLE_FORMAT, SITE, $pageTitle)?></title>
<?php }
mattarnzen replied on at Permalink Reply
mattarnzen
I ran into this too. To have the site name AFTER the title (which this sample code above doesn't do) do this:

<?php
if ($akt) {
$pageTitle = htmlspecialchars($akt, ENT_COMPAT, APP_CHARSET);
?> <title><?php echo sprintf(PAGE_TITLE_FORMAT, $pageTitle, SITE)?></title>
<?php } else {
$pageTitle = htmlspecialchars($c->getCollectionName(), ENT_COMPAT, APP_CHARSET);
?> <title><?php echo sprintf(PAGE_TITLE_FORMAT, $pageTitle, SITE)?></title>
<?php }
JohntheFish replied on at Permalink Reply
JohntheFish
If you want an addon to do this for you, Magic Heading can do that sort of stuff:

http://www.concrete5.org/marketplace/addons/magic-heading/...