Jump to content


Photo

Breadcrumbs in <title></title> tag


  • Please log in to reply
5 replies to this topic

#1 nikola

nikola

    Sr. Member

  • Members
  • PipPipPipPip
  • 224 posts
  • 81

  • LocationZagreb, Croatia

Posted 01 November 2011 - 03:47 PM

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.
Check out my ProcessWire admin themes: Futura Remixed Admin Theme / Moderna Admin Theme / Futura Admin Theme

#2 adamkiss

adamkiss

    Master of the universe

  • Moderators
  • 1,086 posts
  • 291

Posted 01 November 2011 - 05:40 PM

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

#3 ryan

ryan

    Hero Member

  • Administrators
  • 5,980 posts
  • 3383

  • LocationAtlanta, GA

Posted 01 November 2011 - 05:49 PM

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>


#4 thomassausen

thomassausen

    Distinguished Member

  • Members
  • PipPip
  • 32 posts
  • 17

  • LocationBonn, Germany

Posted 30 January 2013 - 01:53 PM

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>

 

?



#5 SiNNuT

SiNNuT

    Sr. Member

  • Members
  • PipPipPipPip
  • 378 posts
  • 236

Posted 31 January 2013 - 05:48 AM

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>";
}

 



#6 ryan

ryan

    Hero Member

  • Administrators
  • 5,980 posts
  • 3383

  • LocationAtlanta, GA

Posted 31 January 2013 - 10:04 AM

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






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users