How can I get a different image size, if all I have is the link?

I decided to use this, which is based on @AndresYanez’s answer: function get_image_id_by_link($link) { global $wpdb; $link = preg_replace(‘/-\d+x\d+(?=\.(jpg|jpeg|png|gif)$)/i’, ”, $link); return $wpdb->get_var(“SELECT ID FROM {$wpdb->posts} WHERE BINARY guid=’$link'”); } This is much more succinct (since it doesn’t jump through the hoops of first removing the extension and then adding it back in), and is … Read more

Get source from the_post_thumbnail

Get post thumbnail url with multisite If you want to display materials on multisite function without switch_blog_id, then output the image material standard features wordpress fail. For this, I wrote this little function as a turnkey solution is nowhere found. function multisite_thumb_url($pid, $bid){ //$pid – post id, $bid – blog id if(isset($pid) && $pid>0){ if(isset($bid) … Read more

Add ‘if exists’ to filter

You want has_post_thumbnail. add_filter( ‘the_content’, insert_featured_image, 20 ); function insert_featured_image( $content ) { global $post; if (has_post_thumbnail($post->ID)) { $content = preg_replace( “/<\/p>/”, “</p>” . get_the_post_thumbnail($post->ID, ‘post-single’), $content, 1 ); } return $content; } Note: The code above is from the post referenced in the OP, but with the has_post_thumbnail conditional. I also had to add … Read more

Featured Images on Front Page

Two categories should do the trick. Featured posts – This category should be applied to posts that you want to show on your home page, with that images grid. You can limit the number of posts (so only the, for example, 6 newest ones would appear) and select the featured image for them on each … Read more

How to make thumbnail images click into blog posts

Do you want to make all the thumbnails link to their respective blog posts? If so, use the following code in the functions.php file: add_filter( ‘post_thumbnail_html’, ‘my_post_image_html’, 10, 3 ); function my_post_image_html( $html, $post_id, $post_image_id ) { $html=”<a href=”” . get_permalink( $post_id ) . ‘” title=”‘ . esc_attr( get_post_field( ‘post_title’, $post_id ) ) . ‘”>’ … Read more