Archivio

Posts Tagged ‘seo’

Using microdata RDFa with Breadcrumb NavXT 4.4 (schema.org)

agosto 8, 2013 3 commenti

I’ve worked hard to accomplish to set up RDFa microdata in Breadcrumb NavXT plugin on my WordPress site (http://gak.it) for a structured data breadcrumb (for Google seo and serp).
I’ve searched on internet and found these very interesting articles:

But they where not working because of the new 4.3 version  of Breadcrumb NavXT. Quoting from this article:

Since Breadcrumb NavXT 4.3.0, all settings that can contain HTML are passed through wp_kses(). With this change, only a basic set of acceptable tags and properties within tags were allowed. […] . However, with Breadcrumb NavXT 4.4, a new filter bcn_allowed_html has been introduced to fix this issue.

Finally the right idea was taken from the very same article, and combining all toghether i’ve solved the problem.

At body tag you have to add the red lines. Blue lines are optional. They are an if statemant that check if the plugin is active):

<body <?php if(function_exists(‘bcn_display’)){?>
itemscope itemtype=”http://schema.org/WebPage&#8221;
<?php }?>
<?php body_class(); ?> id=”body”>

In your theme file (in my case is in header.php), near your breadcrumb section you have to wrote the xmlns file.
Red lines are my lines. But you have to have also the blue lines that display the Breadcrumb via bcn_display() function.

<div itemprop=”breadcrumb”>
<span xmlns:v=”http://rdf.data-vocabulary.org/#”&gt;
<?php if(function_exists(‘bcn_display’))
{ bcn_display(); }?>
</span>
</div>

From version 4.3 you also have to set a filter in your function.php theme file, otherwise all the extra-attributes (itemscope, :v,  etc) will be removed. I’ve worked hard these day to finally find this working code (a little be redundant, but i preferred to add more values to tags).

In function.php of your theme you have to add all the following lines:

// 42 – 08/08/2013 – adding a tag to the allowed HTML list for Breadcrumb NavXT

function my_bcn_allowed_html($allowed_html)
{
$allowed_html[‘li’] = array(
‘title’ => true,
‘class’ => true,
‘id’ => true,
‘dir’ => true,
‘align’ => true,
‘lang’ => true,
‘xml:lang’ => true,
‘aria-hidden’ => true,
‘data-icon’ => true,
‘itemref’ => true,
‘itemid’ => true,
‘itemprop’ => true,
‘itemscope’ => true,
‘itemtype’ => true,
‘property’ => true,
‘xmlns:v’ => true
);

$allowed_html[‘span’] = array(
‘title’ => true,
‘class’ => true,
‘id’ => true,
‘dir’ => true,
‘align’ => true,
‘lang’ => true,
‘xml:lang’ => true,
‘aria-hidden’ => true,
‘data-icon’ => true,
‘itemref’ => true,
‘itemid’ => true,
‘itemprop’ => true,
‘itemscope’ => true,
‘itemtype’ => true,
‘rel’ => true,
‘typeof’ => true,
‘property’ => true,
‘xmlns:v’ => true
);

$allowed_html[‘div’] = array(
‘title’ => true,
‘class’ => true,
‘id’ => true,
‘dir’ => true,
‘align’ => true,
‘lang’ => true,
‘xml:lang’ => true,
‘aria-hidden’ => true,
‘data-icon’ => true,
‘itemref’ => true,
‘itemid’ => true,
‘itemprop’ => true,
‘itemscope’ => true,
‘itemtype’ => true,
‘rel’ => true,
‘typeof’ => true,
‘property’ => true,
‘xmlns:v’ => true
);

$allowed_html[‘a’] = array(
‘title’ => true,
‘class’ => true,
‘id’ => true,
‘dir’ => true,
‘align’ => true,
‘lang’ => true,
‘xml:lang’ => true,
‘aria-hidden’ => true,
‘data-icon’ => true,
‘itemref’ => true,
‘itemid’ => true,
‘itemprop’ => true,
‘itemscope’ => true,
‘itemtype’ => true,
‘rel’ => true,
‘typeof’ => true,
‘property’ => true,
‘xmlns:v’ => true,
‘href’ => true
);

return $allowed_html;
}
add_filter(‘bcn_allowed_html’, ‘my_bcn_allowed_html’);

if you know what are you doing you can also add or remove some attribute, but be carefull, these values override the default ones, so e.g. if you remove the href attribute from the <a> tag it will be automatically stripped. It will be indeed no more recognized because the default values where overriden.

For verifying the correct results, you can use the Google Structured Data Testing Tool

Enjoy ^_^