It is already known, that Magento's SEO is not amazing. That's the reason why I do some pieces of code to make it better:) Here is an another solution, which allows Magento have different titles and descriptions (metadata) in the category sub-pages while layered navigation is in use. By default, there's no matter how many times we will pass filtering by products attributes - metadata will always remain the same and this is one of the common reason for Google to consider these pages as a duplicate content;)
Just put in the following code into the file:
app/code/local/Mage/Page/Block/Html/Head.php
While using this method, all the active filters names and values of current navigation layer are passed to the variable $layerFilters. In addition, this method supports such values as the sort and pagination variables.
public $layerFilters;
public $currentFilters;
public $orderBy;
public $currentPage;
public function getLayersMeta(){
$this->layerFilters = '';
$state_block = $this->getLayout()->createBlock("catalog/layer_state");
$this->currentFilters = $state_block->getActiveFilters();
if(!empty($this->currentFilters)) {
foreach($this->currentFilters as $filter) {
$this->layerFilters .= ($this->layerFilters!='') ? ', '.$filter->getName() : $filter->getName();
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $filter->getFilter()->getRequestVar());
foreach($attribute->getSource()->getAllOptions(true, true) as $option) {
if($filter->getValue() == $option['value']) {
$this->layerFilters .= ' - '.strtr($option['label'],array('"'=>"''"));
}
}
}
$this->layerFilters = ($this->layerFilters!='') ? $this->__('Shopping by: ').$this->layerFilters.' - ' : '';
}
$this->orderBy = '';
if($this->getRequest()->getParam('order') && $this->getRequest()->getParam('dir')) {
$this->orderBy .= $this->__('Sort by ').$this->__(htmlspecialchars($this->getRequest()->getParam('order')));
$this->orderBy .= (htmlspecialchars($this->getRequest()->getParam('dir')) == 'asc') ? ', '.$this->__('ascending') : ', '.$this->__('descending');
}
if($this->getRequest()->getParam('limit') && is_numeric($this->getRequest()->getParam('limit'))) {
$this->orderBy .= (($this->orderBy!='') ? ', ' : $this->__('show')).' '.$this->getRequest()->getParam('limit').' '.$this->__('per page');
}
if($this->getRequest()->getParam('p') && is_numeric($this->getRequest()->getParam('p'))) {
$this->currentPage = $this->__('Page').' '.$this->getRequest()->getParam('p').' - ';
}
$this->orderBy = ($this->orderBy!='') ? $this->orderBy.' - ' : '';
return $this->layerFilters.$this->orderBy.$this->currentPage;
}
Next step will by slight modification of two methods in the same file (getDescription() oraz getTitle()) in this way:
public function getDescription()
{
if (empty($this->_data['description'])) {
$this->_data['description'] = Mage::getStoreConfig('design/head/default_description');
}
return $this->getLayersMeta().$this->_data['description'];
}
public function getTitle()
{
if (empty($this->_data['title'])) {
$this->_data['title'] = $this->getDefaultTitle();
}
return $this->getLayersMeta().htmlspecialchars(html_entity_decode(trim($this->_data['title']), ENT_QUOTES, 'UTF-8'));
}
Thankfully, we got absolutely unique metadata in category products list according to layer and sorting filters. Example of usage this modification can be found in an online bike shop 123bikes.eu ie. in category mountain bikes.
There is no problem to use this code to generate random content in a category page (like in 123bikes.eu between category images and product list). That's another unique content for Google :)
Let the Magento SEO power grows up! :)
Comments
Jason M.
11-05-2012 19:19
check website safe
01-05-2012 17:20
Great post!
DesignEnd
09-01-2012 19:57
Magento中文
09-01-2012 19:41
In Magento ver. 1.6.0.0
display error:
Fatal error: Cannot redeclare Mage_Page_Block_Html_Head::getDescription() in
Marco
06-12-2011 20:19
el Audio Media
23-11-2011 15:36
thanks for this entry. What do you think about the following issue:
1. fixed URL hubs for the layered navigation elements in an specified ordering +
2. the posibility to place special category text for each hub that is builed out of the layered navigation ?
That would be amazing with your edits in common.
All the best,
Chris
internet marketing advies
06-10-2011 12:16
M Line matrassen
01-09-2011 12:10
Grtz from Holland
lelo
19-07-2011 22:00
Magento中文
17-07-2011 13:53
chinese:http://www.magentochinese.org/%E4%BD%BFmagento%E7%9A%84%E5%B1%82%E5%AF%BC%E8%88%AA%E5%AF%B9%E6%90%9C%E7%B4%A2%E5%BC%95%E6%93%8E%E6%9B%B4%E5%8F%8B%E5%A5%BD/
demonkoryu
14-06-2011 11:33
Mike
22-04-2011 10:29
I think that the price attribute options (the range itself) is not showing in meta. It\'s also not showing in the demo sample you showed as a reference. Any ideas how to show it correctly as the option itself (as this is the most used filter, and it will create a duplicate content issue).
Thanks
Mike
20-04-2011 22:39
I've implemented it successfully and it working, but how can I add the actual attribute vlaues to the meta desc/title? Since in the current status, if one clicks on either one of the price ranges, the meta tags are identical since the actual price range (lables) are not inserted... so still it would act as duplicate meta title according to the SE's.
I have tried doing it myself but as I am not a programmer, I could not find the getLabel of the actual attribute and to implement it.
Can you help with that?
Thanks a lot.
Mike
eCom
26-12-2010 11:36
I was wondering if / how / what code will also make the same impact while using the layered navigation. I think that the best approach to do this would be according the label of the attribute in the store view ( I'm not a coder, just know how to "dig").
Can you help on this one or is it too complicated (mag 1.4.1.1)?
Cheers!
DesignEnd
24-11-2010 00:01
Magento has three common code "namespaces". These are: community, core and local.
So I must say - you're wrong;)
On the other hand, I've got no idea, why you had a blank screen, however I see, that it's workin' right now in you web store.
Nicolas
19-11-2010 15:53
Our Magento is a ver. 1.3.2.2, is it something wrong ?
Last thing, there is a mistake on the first step of this tip.
I think the right directory is :
app/code/core/local/Mage/Page/Block/Html/Head.php
and not
app/code/local/Mage/Page/Block/Html/Head.php
DesignEnd
26-10-2010 00:52
Mark
21-10-2010 20:41
DesignEnd
15-09-2010 21:53
sure there's no problem with including pagination in the metadata:)
Just put into the getLayersMeta() method a few lines of code:
if($this->getRequest()->getParam('p') &&
is_numeric($this->getRequest()->getParam('p'))) {
$this->currentPage = $this->__('Page').' ';
$this->currentPage .= $this->getRequest()->getParam('p').' - ';
}
Function in this post is up to date, so copy into your Head.php and have fun with Google:)
Cheers:)
DOB
12-09-2010 23:10
However I was wondering if you could maybe post some information about how to do the same for pagination variables.
Thanks for the information. Great post!
Leave a comment