echo the embeded image on open graph
-
I’m trying to get the url of an embeded image for open graph when the post is shared.
I have been on this for months!!!! I need help. I can get the title page and the content from single posts but the image will not come through as the url for the embedThe blog I need help with is: (visible only to logged in users)
-
Hi joshreid76,
Could you provide me with the link to the post? I’d like to run it through Facebook’s debugger tool. https://developers.facebook.com/tools/debug/
Facebook does a great job of providing comprehensive errors for why an image is not coming through.
Pauline
-
Hi Pauline I know about facebook debugger tool. If its just a single url image it works fine. The problem is the code to find the url off the embedded image.
The debugger reads :Provided og:image URL, was not a valid URL.The content and the title change from post to post with this code below
function fb_opengraph() { global $post; if(is_single()) { if(has_post_thumbnail($post->ID)) { $img_src = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'medium'); } else { $img_src = get_stylesheet_directory_uri() . '/img/opengraph_image.jpg'; } if($excerpt = $post->post_excerpt) { $excerpt = strip_tags($post->post_excerpt); $excerpt = str_replace("", "'", $excerpt); } else { $excerpt = get_bloginfo('description'); } ?> <meta property="og:title" content="<?php echo the_title(); ?>"/> <meta property="og:description" content="<?php echo $excerpt; ?>"/> <meta property="og:type" content="article"/> <meta property="og:url" content="<?php echo the_permalink(); ?>"/> <meta property="og:site_name" content="<?php echo get_bloginfo(); ?>"/> <meta property="og:image" content="<?php echo $img_src; ?>"/> <?php } else { return; } } add_action('wp_head', 'fb_opengraph', 5);Hope this explains better
-
Hi joshreid76,
Please check this thread, https://wordpress.stackexchange.com/questions/9175/how-do-i-get-image-url-only-on-the-post-thumbnail.
I would like to explain that
wp_get_attachment_image_src()returns an array. So, to extract the URL of the image, you just need to use the first index of the array.Hope that helps!
-
Hi archanasolanki11
Thanks so much for your info, i have tried a few different combinations of this and i still can not get it to work. not sure what to try next maybe I am on the wrong array i don’t know now my brain is fried haha
-
Does it matter that the image is from youtube? and do i have to have another code to grab that image?
-
Does it matter that the image is from youtube?
Not sure about this.
do I have to have another code to grab that image?
There is no harm in trying if you have any other script.
I would like to ask you, are you looking for help for joshreid76.wordpress.com? Or is it another site?
Just to inform you, forum support provided here is dedicated to the sites hosted with WordPress.com. We have another dedicated forum for sites that are self-hosted. You can post your query there and there are people who would love to help you!
-
All im trying to do is when i post from a page on my website that the ebedded image url from a youtube image comes up in the open graph as the image.
Oh no its a site i have wordpress installed. This is the 3 forum i have been on how do i find the right one?? -
Oh no its a site i have wordpress installed. This is the 3 forum i have been on how do i find the right one??
Please post your query here at https://wordpress.org/support/. People out there would love to help you with this.
Hope you get a solution soon!
- The topic ‘echo the embeded image on open graph’ is closed to new replies.