Plugin Directory

Changeset 664543


Ignore:
Timestamp:
02/06/2013 09:34:05 PM (13 years ago)
Author:
Bit51
Message:

Improved meta data

File:
1 edited

Legend:

Unmodified
Added
Removed
  • share-center-pro/trunk/share-center-pro.php

    r642695 r664543  
    44    Plugin URI: http://bit51.com/software/share-center-pro/
    55    Description: Add common social sharing services in a widget to be used anywhere on your page or at the bottom of your posts or other content.
    6     Version: Dev
     6    Version: 2.4.2
    77    Text Domain: share-center-pro
    88    Domain Path: /languages
     
    146146            global $scpoptions, $posts, $post;
    147147           
    148 
    149             $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
    150 
    151             if ( is_array( $thumbnail ) && strlen( $thumbnail[0] ) > 1 ) {
    152 
    153                 $thumbnail = $thumbnail[0];
    154 
    155             } else { //get a thumbnail from an image in the post
    156 
    157                 $content = $posts[0]->post_content;
     148            if ( is_singular() || is_front_page() || is_home() ) {
     149
     150
     151                $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
     152
     153                if ( is_array( $thumbnail ) && strlen( $thumbnail[0] ) > 1 ) {
     154
     155                    $thumbnail = $thumbnail[0];
     156
     157                } else { //get a thumbnail from an image in the post
     158
     159                    $content = $posts[0]->post_content;
     160                   
     161                    $output = preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches );
     162
     163                    if ( $output > 0 ) {
     164                        $thumbnail = $matches[1][0];
     165                    } else {
     166                        $thumbnail = '';
     167                    }
     168
     169                }
     170
     171                echo '<!--## Begin Share Center Pro Scripts ## -->' . PHP_EOL;
     172
     173                //add FaceBook OpenGraph Data
     174                if ( $scpoptions['fbog'] == 1 ) {
     175                       
     176                    if( is_singular() ) {
     177
     178                        echo '<meta property="og:title" content="' . get_the_title( $post->ID ) . '" />' . PHP_EOL;
     179                        echo '<meta property="og:url" content="' . get_permalink( $post->ID ) . '" />' . PHP_EOL;
     180                        echo '<meta property="og:type" content="article"/>' . PHP_EOL;
     181                        echo '<meta property="og:description" content="' . strip_tags( the_description() ) . '" />' . PHP_EOL;
     182
     183                    } else {
     184                       
     185                        echo '<meta property="og:url" content="' . get_site_url() . '" />' . PHP_EOL;
     186                        echo '<meta property="og:title" content="' . get_bloginfo() . '" />' . PHP_EOL;
     187                        echo '<meta property="og:type" content="website"/>' . PHP_EOL;
     188                        echo '<meta property="og:description" content="' . get_bloginfo( 'description' ) . '" />' . PHP_EOL;
     189
     190                    }
     191
     192                    echo '<meta property="og:locale" content="' . get_bloginfo( 'language' ) . '" />' . PHP_EOL;
     193                       
     194                    if ( strlen( $thumbnail ) > 1 ) { //only display thumbnail if an image is used
     195                        echo '<meta property="og:image" content="' . $thumbnail . '" />' . PHP_EOL;
     196                    }
     197
     198                    echo '<meta property="og:site_name" content="' . get_bloginfo() . '" />' . PHP_EOL;
     199                   
     200                    if ( strlen( get_the_author() > 1 ) ) { //only display author if needed
     201                        echo '<meta property="og:author" content="' . get_the_author() . '" />' . PHP_EOL;
     202                    }
     203                   
     204                    if ( strlen( $scpoptions['fbappid'] > 1 ) ) {
     205                        echo '<meta property="fb:app_id" content="' . $scpoptions['fbappid'] . '" />' . PHP_EOL;
     206                    }
     207
     208                }
     209
     210                //add Twitter card  Data
     211                if ( $scpoptions['tcmd'] == 1 )  {
    158212               
    159                 $output = preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches );
    160 
    161                 if ( $output > 0 ) {
    162                     $thumbnail = $matches[1][0];
    163                 } else {
    164                     $thumbnail = '';
    165                 }
    166 
    167             }
    168                
    169             echo "<!--## Begin Share Center Pro Scripts ## -->\n";
    170 
    171             //add FaceBook OpenGraph Data
    172             if ( $scpoptions['fbog'] == 1 ) {
    173                    
    174                 echo "<meta property=\"og:title\" content=\"" . get_the_title( $post->ID ) . "\"/>\n" .
    175                     "<meta property=\"og:type\" content=\"article\"/>\n" .
    176                     "<meta property=\"og:url\" content=\"" . get_permalink( $post->ID ) . "\"/>\n" .
    177                     "<meta property=\"og:locale\" content=\"" . get_bloginfo( 'language' ) . "\"/>\n";
    178                    
    179                 if ( strlen( $thumbnail ) > 1 ) { //only display thumbnail if an image is used
    180                     echo "<meta property=\"og:image\" content=\"" . $thumbnail . "\"/>\n";
    181                 }
    182 
    183                 echo "<meta property=\"og:site_name\" content=\"" . get_bloginfo() . "\"/>\n";
    184                
    185                 if ( strlen( get_the_author() > 1 ) ) { //only display author if needed
    186                     echo "<meta property=\"og:author\" content=\"" . get_the_author() . "\" />\n";
    187                 }
    188                
    189                 if ( is_home() || is_front_page() ) {
    190                     echo "<meta property=\"og:description\" content=\"" . get_bloginfo( 'description' ) . "\"/>\n";
    191                 } else if ( is_singular() ) {
    192                     echo "<meta property=\"og:description\" content=\"" . strip_tags( get_the_excerpt() ) . "\"/>\n";
    193                 }
    194                
    195                 if ( strlen( $scpoptions['fbappid'] > 1 ) ) {
    196                     echo "<meta property=\"fb:app_id\" content=\"" . $scpoptions['fbappid'] . "\" />\n";
    197                 }
    198 
    199             }
    200 
    201             //add Twitter card  Data
    202             if ( $scpoptions['tcmd'] == 1 ) {
    203            
    204                 echo "<meta name=\"twitter:card\" content=\"summary\">\n";
    205 
    206                 if ( strlen( $scpoptions['twitteruser'] > 1 ) ) {
    207                     echo "<meta name=\"twitter:site\" content=\"@" . $scpoptions['twitteruser'] . "\">\n";
    208                 }
    209 
    210                 if ( is_home() || is_front_page() ) {
    211                     echo "<meta property=\"twitter:description\" content=\"" . get_bloginfo( 'description' ) . "\"/>\n";
    212                 } else if ( is_singular() ) {
    213                     echo "<meta property=\"twitter:description\" content=\"" . strip_tags( get_the_excerpt() ) . "\"/>\n";
    214                 }
    215 
    216                 echo "<meta property=\"twitter:title\" content=\"" . get_the_title( $post->ID ) . "\"/>\n";
    217                 echo "<meta property=\"twitter:url\" content=\"" . get_permalink( $post->ID ) . "\"/>\n";
    218 
    219             }
    220 
    221             echo "<!--## End Share Center Pro Scripts ## -->\n";
     213                    echo '<meta name="twitter:card" content="summary" />' . PHP_EOL;
     214
     215                    if ( strlen( $scpoptions['twitteruser'] > 1 ) ) {
     216                        echo '<meta name="twitter:site" content="@' . $scpoptions['twitteruser'] . '" />' . PHP_EOL;
     217
     218                        if( is_singular() ) {
     219
     220                            echo '<meta property="twitter:title" content="' . get_the_title( $post->ID ) . '" />' . PHP_EOL;
     221                            echo '<meta property="twitter:url" content="' . get_permalink( $post->ID ) . '" />' . PHP_EOL;
     222                            echo '<meta property="twitter:description" content="' . strip_tags( the_description() ) . '" />' . PHP_EOL;
     223
     224                        } else {
     225                           
     226                            echo '<meta property="twitter:url" content="' . get_site_url() . '" />' . PHP_EOL;
     227                            echo '<meta property="twitter:title" content="' . get_bloginfo() . '" />' . PHP_EOL;
     228                            echo '<meta property="twitter:description" content="' . get_bloginfo( 'description' ) . '" />' . PHP_EOL;
     229
     230                        }
     231
     232                    }
     233
     234                }
     235
     236                echo '<!--## End Share Center Pro Scripts ## -->' . PHP_EOL;
     237
     238            }
    222239
    223240        }
Note: See TracChangeset for help on using the changeset viewer.