Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter mferris77

    (@mferris77)

    Well, that was quick. Looks like there’s a useful function to reset the global post ID back to the original query. Simply adding “wp_reset_postdata();” to the beginning of the function works for me.

    I also identified another problem. I wondered why the og:image associated with my post was getting selected as I have a number of images in a particular post and it was choosing the last image in the post. Looks like there is some problems with the image code as well. OpenGraph protocol says we should be able to have multiple images associated with a post, this allows users to select the image to use when sharing something on facebook (I believe). The plugin first attempts to find a ‘post thumbnail’ (now referred to as the featured image). If it does, it stores that image to an array. It then runs a function to parse the rest of the post for images and correctly returns those images and adds them to the array of images for the post. However, the error is when it loops through all of these images to make the multiple og:image tags. Rather than append to the output string, it simply overwrites the string each time, and that is why the last image in my post is what was being used for the og:image tag.

    Note: One additional change I made: The featured image being retrieved was the ‘thumbnail’ version, which for me, was 150px x 150px. When I run this through the facebook debugger, it raises an error saying the images should be at least 200px on each side. I went ahead and changed the call to ‘wp_get_attachment_image_src()’ to use ‘medium’ instead of ‘thumbnail’. I don’t know enough about opengraph implementation in other platforms to know whether we should be using small thumbnails or offer larger images, so I’ll leave that up to the developer and/or other users to determine what it really should be set to. This change is reflected in my copy of the function below.

    Below is the entire fixed and working (for me) ‘nxs_ogtgCallback’ function which begins on line 796 of NextScripts_SNAP.php, version 2.6.3:

    function nxs_ogtgCallback($content){ global $post, $plgn_NS_SNAutoPoster;  if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;    $ogimgs = array();
    	wp_reset_postdata();
      if (stripos($content, 'og:title')!==false) $ogOut = "\r\n"; else {
        $title = preg_match( '/<title>(.*)<\/title>/', $content, $title_matches );
        if ($title !== false && count( $title_matches) == 2 ) $ogT ='<meta property="og:title" content="' . $title_matches[1] . '" />'."\r\n"; else {
          if (is_home() || is_front_page() )  $ogT = get_bloginfo( 'name' ); else $ogT = get_the_title();
          $ogT =  '<meta property="og:title" content="' . esc_attr( apply_filters( 'nxsog_title', $ogT ) ) . '" />'."\r\n";
        }
        $description = preg_match( '/<meta name="description" content="(.*)"/', $content, $description_matches );
        if ( $description !== false && count( $description_matches ) == 2 ){
        	 $ogD = '<meta property="og:description" content="' . $description_matches[1] . '" />'."\r\n";
        } else {
          if (is_singular()) {
            if(has_excerpt($post->ID))$ogD=strip_tags(nxs_snapCleanHTML(get_the_excerpt($post->ID)));else $ogD= str_replace("  ", ' ', str_replace("\r\n", ' ', trim(substr(strip_tags(nxs_snapCleanHTML(strip_shortcodes($post->post_content))), 0, 200))));
          } else $ogD = get_bloginfo('description');  $ogD = preg_replace('/\r\n|\r|\n/m','',$ogD);
          $ogD = '<meta property="og:description" content="'.esc_attr( apply_filters( 'nxsog_desc', $ogD ) ).'" />'."\r\n";
        }
        $ogSN = '<meta property="og:site_name" content="'.get_bloginfo('name').'" />'."\r\n";
        $ogLoc = strtolower(esc_attr(get_locale())); if (strlen($ogLoc)==2) $ogLoc .= "_".strtoupper($ogLoc);
        $ogLoc = '<meta property="og:locale" content="'.$ogLoc.'" />'."\r\n"; $iss = is_home();
        $ogType = is_singular()?'article':'website'; if($vidsFromPost == false) $ogType = '<meta property="og:type" content="'.esc_attr(apply_filters('nxsog_type', $ogType)).'" />'."\r\n";                  
    
        if (is_home() || is_front_page()) $ogUrl = get_bloginfo( 'url' ); else $ogUrl = 'http' . (is_ssl() ? 's' : '') . "://".$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
        $ogUrl = '<meta property="og:url" content="'.esc_url( apply_filters( 'nxsog_url', $ogUrl ) ) . '" />' . "\r\n";
    
        if (!is_home()) { /*
          $vidsFromPost = nsFindVidsInPost($post); if ($vidsFromPost !== false && is_singular()) {  echo '<meta property="og:video" content="http://www.youtube.com/v/'.$vidsFromPost[0].'" />'."\n";
          echo '<meta property="og:video:type" content="application/x-shockwave-flash" />'."\n";
          echo '<meta property="og:video:width" content="480" />'."\n";
          echo '<meta property="og:video:height" content="360" />'."\n";
          echo '<meta property="og:image" content="http://i2.ytimg.com/vi/'.$vidsFromPost[0].'/mqdefault.jpg" />'."\n";
          echo '<meta property="og:type" content="video" />'."\n";
        } */
          if (function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
            $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
            $ogimgs[] = $thumbnail_src[0];
          }
          $imgsFromPost = nsFindImgsInPost($post, (int)$options['advFindOGImg']==1);
          if ($imgsFromPost !== false && is_singular() && is_array($ogimgs) && is_array($imgsFromPost))  $ogimgs = array_merge($ogimgs, $imgsFromPost);
        }       
    
        //## Add default image to the endof the array
        if ( count($ogimgs)<1 && isset($options['ogImgDef']) && $options['ogImgDef']!='') $ogimgs[] = $options['ogImgDef'];
        //## Output og:image tags
        $ogImgsOut = "";
        if (!empty($ogimgs) && is_array($ogimgs)) foreach ($ogimgs as $ogimage)  $ogImgsOut .= '<meta property="og:image" content="'.esc_url(apply_filters('ns_ogimage', $ogimage)).'" />'."\r\n";
        $ogOut  = "\r\n".$ogSN.$ogT.$ogD.$ogType.$ogUrl.$ogLoc.$ogImgsOut;
      } $content = str_ireplace('<!-- ## NXSOGTAGS ## -->', $ogOut, $content);
      return $content;
    }

    Hope this helps!

    I too had a problem with images not being displayed and it caused me a couple hours of grief. It turns out that another plugin that I use (Bulletproof security) locks down the use of TimThumb when referencing external images. I had to add a rule in my .htaccess file to allow content from pinterest.com. Here’s a link to that discussion if you happen to be using BPS. Thanks for your feedback – I’m glad it helped!

    Hi all – as stephanmonecke mentions, the full description *is* available in the RSS feed but it takes a little ‘massaging’ to get it. I was able to get modify the plugin to make this work. While I was doing it I also identified a few other improvements to the plugin. I’ve made the fully modified plugin available for download but also include instructions on fixing only the description text length discussed in this thread.

    bkmacdaddy, feel free to incorporate this as well as the other changes I’ve made into your plugin. I’ve used comments in the code liberally so you can see what I’ve done. I don’t claim to be a php guru so perhaps there are more elegant solutions for some of the things I’ve done. Other changes I made were:

    – Ability to set the description length (now that the full description is being retrieved)
    – Switched from jQuery resizing of thumbs to use of TimThumb (perhaps a controversial point but a personal preference for me)
    – Ability to switch between normal list display of images to ‘compressed’, basically floating the DIVs left
    – Ability to place the ‘follow me’ button in the title of the widget or at the bottom (where it currently is)
    – Added an optional ‘description’ field so we can insert text below the title of the widget

    Here’s the full instructions and a link is at the bottom for the modified plugin download

    Thread Starter mferris77

    (@mferris77)

    Interesting… that’s kind of what I thought but I was holding out hope that I could somehow modify the page’s content before it went to the screen. I guess not.

    Thanks.. I might actually go with some jQuery to remove just that line from the metabox.

Viewing 4 replies - 1 through 4 (of 4 total)