I'm working on an old version of wordpress 3.9.5.

I Installed a Pintrest plugin "Pinterest Pin It Button On Image Hover And Post" - which just pops-up a share button for pintrest whenever you hover on an image.

I want to make some modifications on this plugin:

Whenever you view the blog page with all the blog posts, and you hover over the featured image before even displaying the whole post - you can see the button on hover.

I want to make it show up ONLY when you enter a single blog post and view the whole post.

This is the .php file in the plugin:

 * Plugin Name: Pinterest Pin It Button On Image Hover And Post
 * Version: 1.2
 * Description: Pin Your WordPress Blog Posts Pages Images With Pinterest
 * Author: Weblizar
 * Author URI: http://weblizar.com/plugins/
 * Plugin URI: http://weblizar.com/plugins/pinterest-pin-it-button/
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

 * Constant Values & Variables
define("WEBLIZAR_PINIT_PLUGIN_URL", plugin_dir_url(__FILE__));
define("WEBLIZAR_PINIT_TD", "weblizar_pinit");

 * Default Setting
register_activation_hook( __FILE__, 'PiniIt_DefaultSettings' );
function PiniIt_DefaultSettings(){
    add_option("WL_Enable_Pinit_Post", 1);
    add_option("WL_Enable_Pinit_Page", 1);
    add_option("WL_Pinit_Btn_On_Hover", "true");
    add_option("WL_Pinit_Btn_Color", "red");
    add_option("WL_Pinit_Btn_Design", "rectangle");
    add_option("WL_Pinit_Btn_Size", "small");

//Load saved pin it button settings
$PinItOnHover   = get_option("WL_Pinit_Btn_On_Hover");
if($PinItOnHover == "true"){ 
    // Add hook for frontend <head></head>
    add_action('wp_head', 'wl_pinit_js');
function wl_pinit_js() {
    $PinItOnHover       = get_option("WL_Pinit_Btn_On_Hover");
    $PinItColor = get_option("WL_Pinit_Btn_Color");
    $PinItSize      = get_option("WL_Pinit_Btn_Size");
    ?><script type="text/javascript" async defer  data-pin-color="<?php echo $PinItColor; ?>" <?php if($PinItSize == "large") { ?>data-pin-height="28"<?php }?> data-pin-hover="<?php echo $PinItOnHover; ?>" src="<?php echo WEBLIZAR_PINIT_PLUGIN_URL."js/pinit.js"; ?>"></script><?php

//Add Pin It Button After Post Content
function Load_pin_it_button_after_post_content($content){
    if (is_single()) {
        //check for enable post pin it button
        $PinItPost      = get_option("WL_Enable_Pinit_Post");
        if(get_option("WL_Enable_Pinit_Post")) {
            $content .= '<p><a href="//www.pinterest.com/pin/create/button/" data-pin-do="buttonBookmark"  data-pin-color="red" data-pin-height="28"><img src="//assets.pinterest.com/images/pidgets/pinit_fg_en_rect_red_28.png" /></a></p>';
    return $content;
add_filter( "the_content", "Load_pin_it_button_after_post_content" );

//Add Pin It Button After Page Content
function Load_pin_it_button_after_page_content($content){
    if (!is_single()) {
        //check for enable page pin it button
        $PinItPage      = get_option("WL_Enable_Pinit_Page");
        if(get_option("WL_Enable_Pinit_Page")) {
            $content .= '<p><a href="//www.pinterest.com/pin/create/button/" data-pin-do="buttonBookmark"  data-pin-color="red" data-pin-height="28"><img src="//assets.pinterest.com/images/pidgets/pinit_fg_en_rect_red_28.png" /></a></p>';
    return $content;

add_filter( "the_content", "Load_pin_it_button_after_page_content" );

 * Plugin Settings Admin Menu

function WL_PinItButtonPage() {
    $PinItAdminMenu = add_menu_page( __('Pinterest PinIt Button Settings', WEBLIZAR_PINIT_TD), __('Pinterest PinIt Button', WEBLIZAR_PINIT_TD), 'administrator', 'pinterest-pinit-button-on-hover', 'pinterest_pinit_button_settings_page', 'dashicons-admin-post');
    add_action( 'admin_print_styles-' . $PinItAdminMenu, 'PiniIt_Menu_Assets' );

 * Load PinItAdminMenu Pages Assets JS/CSS/Images
function PiniIt_Menu_Assets() {
     * All Required CSS & JS  Files
    wp_enqueue_style('bootstrap_css', WEBLIZAR_PINIT_PLUGIN_URL.'css/bootstrap.css');
    wp_enqueue_style('weblizar-smartech-css', WEBLIZAR_PINIT_PLUGIN_URL.'css/weblizar-smartech.css');
    wp_enqueue_style('font-awesome_min', WEBLIZAR_PINIT_PLUGIN_URL.'font-awesome/css/font-awesome.min.css');
    wp_enqueue_style('font-animate', WEBLIZAR_PINIT_PLUGIN_URL.'css/animate.css');


function pinterest_pinit_button_settings_page() {

add_action( 'wp_ajax_save_pinit', 'PinItSaveSettings' );
function PinItSaveSettings() {
    update_option("WL_Enable_Pinit_Post", $_POST['PinItPost']);
    update_option("WL_Enable_Pinit_Page", $_POST['PinItPage']);
    update_option("WL_Pinit_Btn_On_Hover", $_POST['PinItOnHover']);
    update_option("WL_Pinit_Btn_Design", $_POST['PinItDesign']);
    update_option("WL_Pinit_Btn_Color", $_POST['PinItColor']);
    update_option("WL_Pinit_Btn_Size", $_POST['PinItSize']);
} ?>

So I noticed the functions already have: if (is_single()) { but still show up when hovering over images in the main blog page although your not viewing the page itself.

I went through the 'Conditional Tags' https://codex.wordpress.org/Conditional_Tags and didn't find any solution for this.

How do I activate this plugin ONLY on images viewed in a post (after you open it and not in the main blog page or sidebar)?

  • see the next block of code !is_single() perhaps this is your problem? - looks like it might be an option in the settings admin to switch this though based on option WL_Enable_Pinit_Page – Benny May 6 '15 at 11:41
  • @TheCellarRoom Hi, I used if (!is_single($post)) { too, and I still get the same result. Any idea why? – Kar19 May 10 '15 at 8:37
  • Your code uses is_single and !is_single ~ so all the time even on archive and index page. Better to use is_page for actual pages – Benny May 10 '15 at 9:51
  • is_page works on vied posts?!?!?! – Kar19 May 10 '15 at 9:52
  • I changed it to is_page() and I still get the same result – Kar19 May 10 '15 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.