Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: WP JS Plus One
- Version: 1.0
- Description: Adds Google's +1 button to posts using JavaScript
- Author: konqi
- Author URI: http://www.konqi.de
- License: Public Domain
- */
- /* Version Check */
- global $wp_version;
- $exit_msg='WP JS PlusOne This requires Wordpress 2.5 or newer.' .
- '<a href="http://codex.wordpress.org/Upgrading_Wordpress">Please update!</a>';
- if (version_compare($wp_version,"2.5","<"))
- {
- exit ($exit_msg);
- }
- /* Adds the injection script to the Header of your Theme */
- function wpjsplusonethis() {
- echo '<script type="text/javascript">
- <!--
- function replaceGooglePlusLinks(elementID, postLink)
- {
- targetElement = document.getElementById(elementID);
- if(targetElement != undefined && targetElement != null)
- {
- targetElement.innerHTML = "<g:plusone size=\"small\" href=\"" + postLink +"\"></g:plusone>";
- targetElement.setAttribute("style","display:inline;float:right;margin-left:1em;");
- }
- }
- -->
- </script>';
- echo '<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>' . "\n";
- }
- function WPPlusOneThis_Link()
- {
- global $post;
- global $googlejsplusonethis;
- // Insert place holder
- echo '<div id="googleplusone' . get_the_ID() . '"></div>' . "\n";
- // get the URL to the post or page
- $googlejsplusonethis .= 'replaceGooglePlusLinks("googleplusone' . get_the_ID() .'" , "'.get_permalink(get_the_ID()).'");' . "\n";
- }
- function wpjsplusonethisfooter()
- {
- // write & execute replacement, let Google do the rest
- global $googlejsplusonethis;
- echo '<script type="text/javascript">
- <!--
- ' . $googlejsplusonethis . '
- -->
- </script>' . "\n";
- }
- function WPJWPlusOne_Filter($content)
- {
- return $content.WPPlusOneThis_Link();
- }
- add_action('wp_head','wpjsplusonethis');
- add_action('wp_footer','wpjsplusonethisfooter');
- /* Show Google Plus One Link in content */
- add_filter('the_content', 'WPJWPlusOne_Filter');
- ?>
Add Comment
Please, Sign In to add comment