I code a little wordpress plugin to add rich snippets support for breadcrumbs for someone.
1. use jQuery
Paste the following code in a javascript file,such as:cwp-flat-ui-seo.js
jQuery(function(){
jQuery('.breadcrumb').attr({'itemscope':'itemscope','itemtype':''}).find('a').attr({'itemprop':'url'});
jQuery('.breadcrumb a').each(function(){
var content_in_tag_a=jQuery(this).html();
jQuery(this).html('').append(''+content_in_tag_a).prepend('');
});
/*下面的仅仅是测试用的!*/
/*alert('aaa');*/
/*END*/
});
2.PHP code for the plugin
/*
**************************************************************************
Plugin Name: Coolwp XXX add-on
Plugin URI:
Description: 这是一个塑料磁力泵.....
Version: 1.0
Author: Suifengtec
Author URI:
Domain Path: /lang/
**************************************************************************
*/
define('CWP_PLUGIN_XXX_ADD_ON_VER','1.0');
add_action('wp_enqueue_scripts','cwp_flat_ui',999);
function cwp_flat_ui(){
wp_register_style('cwp-flat-ui', plugins_url('css/css.css', __FILE__) ,false, CWP_PLUGIN_XXX_ADD_ON_VER, 'all' ); //you may ignore this css file
wp_register_script('cwp-flat-ui-seo', plugins_url('js/cwp-flat-ui-seo.js', __FILE__), array('jquery'),CWP_PLUGIN_XXX_ADD_ON_VER,true); //it is!
wp_enqueue_style( 'cwp-flat-ui'); //you may ignore this css file
wp_enqueue_script('cwp-flat-ui-seo'); //it is!
}
Notice: Your breadcrumbs navigation should be wrapped in a div which has a class "breadcrumbs", under normal circumstances is that, if your theme is not in case , you need to modify the selector in the above js code.
Thanks! bear with my poor english.
阅读(1392) | 评论(0) | 转发(0) |