Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function insert_fb_image_fix() {
- global $post;
- if ( !is_singular())
- return;
- if(!has_post_thumbnail( $post->ID )) {
- $files = get_children('post_parent='.get_the_ID().'&post_type=attachment&post_mime_type=image&order=desc');
- if($files) :
- $keys = array_reverse(array_keys($files));
- $j=0;
- $num = $keys[$j];
- $image=wp_get_attachment_image($num, 'medium', true);
- $imagepieces = explode('"', $image);
- $imagepath = $imagepieces[1];
- $main=wp_get_attachment_url($num);
- echo '<meta property="og:image" content="' . $main . '"/>';
- endif;
- }
- else{
- $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' );
- echo '<meta property="og:image" content="' . esc_attr( $thumbnail_src[0] ) . '"/>';
- }
- echo "";
- }
- add_action( 'wp_head', 'insert_fb_image_fix', 5 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement