Jump to content

Breadcrumbs in <title></title> tag


nikola
 Share

Recommended Posts

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
Link to comment
Share on other sites

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'.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 1 year later...

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
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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