Not gettin from post-thumbnail
-
This code will fix it:
<?php /* Plugin Name: VK Image Plugin URI: https://ajayver.com Description: Forces vk.com to use the first image from post while sharing a link. Version: 1.1 Author: ajayver Author URI: https://ajayver.com */ add_action('wp_head', 'add_image_for_vk'); function add_image_for_vk() { if (is_single()) { global $post; $current_post = get_post( $post->ID ); $thumbnail_id = get_post_thumbnail_id($current_post->ID); if ($thumbnail_id) { $post_attachment = wp_get_attachment_image_src($thumbnail_id, 'post-thumbnail'); $image = reset($post_attachment); } else { $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"]/i', $current_post->post_content, $matches); if (!empty($matches[1][0])) { $image = $matches[1][0]; } else { $image = get_option('vk_default_image'); } } } if(!empty($image)) { echo "<!-- Added by VK Image Plugin -->\n"; echo '<link rel="image_src" href="' . $image . '" />' . "\n"; } } include( plugin_dir_path( __FILE__ ) . 'admin.php');
- The topic ‘Not gettin from post-thumbnail’ is closed to new replies.