Jump to content
nikola

Breadcrumbs in <title></title> tag

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

Share this post


Link to post
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'.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...