Jump to content

Breadcrumbs in <title></title> tag


Recommended Posts

Posted

As you might now it, Google search engine uses <title></title> tag as very relevant source of information about your web site.

Sometimes it's good to use "breadcrumbs" in <title></title> tag to define structure of categories and such.

If you want to use this kind of <title></title> tag instead of regular page title, then you could do the following:

<title><?php
$root = $pages->get('/');
foreach($page->parents()->remove($root)->append($page)->reverse() as $parent) { echo "{$parent->title} - "; }
echo "COMPANY NAME";
?></title>

Replace "COMPANY NAME" with the name of your company etc.

  • Like 1
Posted

It's cool tip – with some cool PageArray modification aswell.

Regarding titles itself; I would never do this, unless it would make total sense for visitor (e.g. some kind of eshop, where I can imagine something like 'Yamaha XZ-200 – Electronic keyboards – keyboards – products) – that looks okay. Otherwise, I am more of fan of 'copywrite for people, not google'.

Posted

Good tip!

Here's another way to do the same thing (using the slice method to trim off home):

<title><?php
foreach($page->parents()->append($page)->slice(1)->reverse() as $parent) { echo "{$parent->title} - "; }
echo "COMPANY NAME";
?></title>
  • Like 1
  • 1 year later...
Posted

Thanks. And if you want this title on homepage:

<title>Company Name - {$parent->title}</title>

And on all other sites:

<title>{$parent->title} - Company Name</title>

?

  • Like 1
Posted

With some conditional logic like

$homepage = $pages->get('/');
if($page === $homepage) {
    echo "<title>Company Name - {$parent->title}</title>";
} else {
    echo "<title>{$parent->title} - Company Name</title>";
}

  • Like 1
Posted

Another way to check for homepage is just if the $page->id === 1; because the homepage always has an ID of 1. 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...