How to pull blogpost image link into Open Graph meta tag?

resolved (8 posts) (3 voices)

  1. janthemanson
    Member

    I'm using the awake 1.3 theme and a plugin called socialize. I wonder how to get the blogpost image link into the open graph meta tag? Especially I like to include a resized (blogpost) image. Resized images are cached by the template, or?

    I found the part where the blogpost image is processed for output in theme-functions.php, but I don't know what to insert or modify in the plugin function.

    So here is the function of the plugin I want to modify:

    function get_properties(){
            global $post;
            $socialize_settings = get_option('socialize_settings10');
            $og_properties = array();
            if(is_singular()){
                $image = '';
     
                if (current_theme_supports('post-thumbnails') && has_post_thumbnail($post->ID)) {
                        $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail');
                        if ($thumbnail) {
                                $image = $thumbnail[0];
                        }
                }
     
                $og_properties = array(
                                    'og:title'                   => $post->post_title,
                                    'og:type'                  => 'article',
                                    'og:url'                     => get_permalink(),
                                    'og:image'               => $image 'here I want the link to the image pull in',
                                    'og:site_name'         => get_bloginfo('name'),
                                    'og:description'       => strip_tags(get_the_excerpt()),
                                    'fb:app_id'              => $socialize_settings['socialize_fb_appid'],
                                    'fb:admins'             => $socialize_settings['socialize_fb_adminid'],
                                    'fb:page_id'           => $socialize_settings['socialize_fb_pageid']
                                     );
     
            }
            return $og_properties;
        }

    Did you have a quick idea to get the original image link or resized image link in there?
    Thanks in advance, Jan

    Posted 9 months ago #
  2. Elliott
    Support

    Hello janthemanson,

    You can use the resize script like so,

    <img src = "http://www.YOUR SITE URL/wp-content/themes/awake/lib/scripts/thumb.php?src=LINK TO YOUR IMAGE&w=200&h=200&q=100&zc=1" />

    Just replace the areas with your own urls. The w and h parameters at the end are for the width and height and the q, zc are for quality and zoom / crop.

    Posted 9 months ago #
  3. janthemanson
    Member

    Thanks, that's cool, but how do I pull in the link dynamically for each blogpost?
    With which variable I get the link to the image, specified in the admin area of each post?
    Sorry, but I'm a noob in php.

    Posted 9 months ago #
  4. Elliott
    Support

    It would depend on how your using it. If the link is different for each post then you could use a custom field in your post / page and this function to grab it,

    http://codex.wordpress.org/Function_Reference/get_post_meta

    Posted 8 months ago #
  5. janthemanson
    Member

    Ah, I think I get it! It's similar to the theme function of the blogpost image, right?

    get_post_meta($post->ID, 'post_image', true);

    So I will set a custom field with a reference-name, hmmmm lets say open_graph and call it by

    get_post_meta($post->ID, 'open_graph', true);
    and insert the image link as value.

    Thanks for the help, I will try this and get you updated about this!
    I always apreciate your great Service here! Thanks again!

    Posted 8 months ago #
  6. janthemanson
    Member

    function get_properties(){
            global $post;
            $socialize_settings = get_option('socialize_settings10');
            $og_properties = array();
            if(is_singular()){
                $image = '';
     
                if (current_theme_supports('post-thumbnails') && has_post_thumbnail($post->ID)) {
                        $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail');
                        if ($thumbnail) {
                                $image = $thumbnail[0];
                        }
                }
     
                $og_properties = array(
                                    'og:title'                   => $post->post_title,
                                    'og:type'                  => 'article',
                                    'og:url'                     => get_permalink(),
                                    'og:image'               => get_post_meta($post->ID, 'open_graph', true),
                                    'og:site_name'         => get_bloginfo('name'),
                                    'og:description'       => strip_tags(get_the_excerpt()),
                                    'fb:app_id'              => $socialize_settings['socialize_fb_appid'],
                                    'fb:admins'             => $socialize_settings['socialize_fb_adminid'],
                                    'fb:page_id'           => $socialize_settings['socialize_fb_pageid']
                                     );
     
            }
            return $og_properties;
        }

    O.k. this will fix it with a custom field. Thanks for your support!
    Btw. did you have any refferal system planned. I like to spread your themes here in Germany, cause I'm exited about the new versions. Maybe I can contribute to some localization?
    Regards, Jan

    Posted 8 months ago #
  7. Elliott
    Support

    That would be great if you could get a german .mo file. One of our customers already translated it to french so we'll see if we can include them both in the next update.

    As for the referral system I don't think we have anything setup yet. I'll flag this topic for Webtreats so we can get a more official answer.

    Posted 8 months ago #
  8. Webtreats
    Support

    Hi janthemanson,

    Glad to hear you're liking the new themes.

    We do have a referral system planed.

    We'll update this thread when it's up and running.

    Posted 8 months ago #

Reply

You must log in to post.

Construct WordPress Theme
Construct wordpress theme
Myriad WordPress Theme
Myriad wordpress theme
Method WordPress Theme
Method wordpress theme
Fusion WordPress Theme
Fusion wordpress theme
Elegance WordPress Theme
Elegance wordpress theme
Echelon WordPress Theme
Echelon wordpress theme
Dejavu WordPress Theme
Dejavu wordpress theme
Modular WordPress Theme
Modular wordpress theme