Created
September 10, 2015 18:21
-
-
Save butlerblog/0ad964bf825d5be46bd6 to your computer and use it in GitHub Desktop.
How to Add keyword density and keyword highlight to admin bar (from: http://wpsnipp.com/index.php/functions-php/add-keyword-density-and-keyword-highlight-to-admin-bar/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment