Plugin Directory

Changeset 2410265


Ignore:
Timestamp:
10/31/2020 08:26:49 AM (5 years ago)
Author:
thumblink
Message:

Updated banners and added twitter card support

Location:
thumblink
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • thumblink/trunk/thumblink.php

    r2407952 r2410265  
    22/**
    33 * @package Thumblink
    4  * @version 1.2
     4 * @version 1.3
    55 */
    66/*
     
    99Description: Thumblink automatically creates thumbnails for all of your blog posts to make your links look better. A link to your WordPress site on platforms like Facebook, Twitter, and LinkedIn is often the first interaction you have with a visitor. The link's thumbnail is 3x larger than its text preview - if it looks ugly or unmaintained, they won't click on it. Thumblink automatically generates these thumbnails by taking a screenshot of each page.
    1010Author: Team Thumblink
    11 Version: 1.2
     11Version: 1.3
    1212Author URI: https://thumblink.com/
    1313*/
     
    1515global $wp;
    1616function hook_thumblink() {
    17         if (has_post_thumbnail()) {
    18                 $post_image = wp_get_attachment_image_src(get_post_thumbnail_id(), "full");
    19                 if (!empty($post_image[0])) {
    20                         $post_image = $post_image[0];
    21                         echo "<meta property=\"og:image\" content=\"{$post_image}\" />";
    22                         return;
    23                 }
     17    $post_title = get_the_title();
     18    echo "<meta name=\"twitter:card\" content=\"summary_large_image\" />\n";
     19    echo "<meta name=\"twitter:title\" content=\"{$post_title}\" />\n";
     20    if (has_post_thumbnail()) {
     21        $post_image = wp_get_attachment_image_src(get_post_thumbnail_id(), "full");
     22        if (!empty($post_image[0])) {
     23            $post_image = $post_image[0];
     24            echo "<meta name=\"twitter:image\" content=\"{$post_image}\" />\n";
     25            echo "<meta property=\"og:image\" content=\"{$post_image}\" />\n";
     26            echo "<meta property=\"og:image:secure_url\" content=\"{$post_image}\" />\n";
     27            return;
    2428        }
    25         $url = get_page_link();
    26         $post = get_post();
    27         if (!is_null($post)) {
    28             if(is_array($post)) {
    29                 $post = $post[0];
    30             }
    31             $url .= "#post-{$post->ID}";
    32         }
    33         $url = urlencode($url);
    34         echo "<meta property=\"og:image\" content=\"https://generate.thumblink.com/?url={$url}\" />";
     29    }
     30    $url = get_page_link();
     31    $post = get_post();
     32    if (!is_null($post)) {
     33        if(is_array($post)) {
     34            $post = $post[0];
     35        }
     36        $url .= "#post-{$post->ID}";
     37    }
     38    $url = urlencode($url);
     39    echo "<meta name=\"twitter:image\" content=\"https://generate.thumblink.com/?url={$url}\" />\n";
     40    echo "<meta property=\"og:image\" content=\"https://generate.thumblink.com/?url={$url}\" />\n";
     41    echo "<meta property=\"og:image:secure_url\" content=\"https://generate.thumblink.com/?url={$url}\" />\n";
    3542}
    3643add_action('wp_head', 'hook_thumblink');
Note: See TracChangeset for help on using the changeset viewer.