X

Add keyword density and keyword highlight to admin bar

Adding this snippet to the functions.php of your wordpress theme will make use of a few JQuery plugins to display keyword density and keyword highlight to your admin bar.



Code Snippet:


function keyword_density_js(){
?>
<script src="<?php bloginfo('template_url'); ?>/js/jquery.js" type="text/javascript"></script>
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery.wordstats.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery.wordstats.en.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/highlight.js"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
var count = 8;
$.extend(jQuery.wordStats.stopWords, {'retrieved': true, '2007': true});
$.wordStats.computeTopWords(count);
var msg = '';
for(var i = 0, j = $.wordStats.topWords.length; i < j && i <= count; i++) {
msg += '<li><a href="#" class="remove" onclick="$(\'#content\').highlight(\''+$.wordStats.topWords[i].substring(1)+'\');"><span id="ab-updates" class="update-count">' + $.wordStats.topWeights[i] + '</span> – ' + $.wordStats.topWords[i].substring(1) + '</a></li>';
}
$('#wp-admin-bar-keyword_style ul').html(msg);
$.wordStats.clear();
});
</script>
<style>.highlight { background-color:yellow;color:#333 !important; }</style>
<?
} add_action( 'wp_head','keyword_density_js' );

function keyword_density_adminbar() {
global $wp_admin_bar;
$keyword_density ='<div id="keyword_stats">error!</div>';

$wp_admin_bar->add_menu( array(
'id' => 'keyword_style',
'title' => __('Keyword Density'),
'href' => admin_url( '#')
) );

$wp_admin_bar->add_menu( array(
'parent' => 'keyword_style',
'id' => 'keyword_style',
'title' => $keyword_density,
'href' => admin_url('#')
) );
}
add_action( 'wp_before_admin_bar_render', 'keyword_density_adminbar' );

You will need to download the following zip file of Javascript plugins for this admin bar hack to work. Just upload them to a folder within your wordpress theme called js located within – wp-content/themes/my_theme/js/

Download (JQuery – plugins)

The wordStats JQuery plugin is from Jean-Francois Hovinne and the highlight plugin is from Johann Burkard

Comments  Leave a Reply

  1. Ernesto Marrero April 28, 2013 at 10:58 pm

    This works in the current version of wordpress? I have not been able to configure it. I have to modify the path? Please …

  2. Elliott the web design guy April 28, 2011 at 5:41 am

    Wow! Another awesome snippet of code, this will be very useful for a number of projects! I love this site =D

    1. Cool Elliott thanks, glad you like the website. Let your friends know about us 🙂

  3. Thank you

    1. no problem glad to help.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!