Display the first image from a post in RSS feed

Here’s what I use in Dave’s WordPress Live Search to get the first image: public static function firstImg( $post_content ) { $matches = array(); $output = preg_match_all( ‘/<img.+src=[\'”]([^\'”]+)[\'”].*>/i’, $post_content, $matches ); if ( isset( $matches[1][0] ) ) { $first_img = $matches[1][0]; } if ( empty( $first_img ) ) { return ”; } return $first_img; }

WordPress resizes image to the same size as uploaded

If you are uploading images the same size as the large size in your WordPress installation, then set your Large size to 0x0 in Settings -> Media or remove this line: add_image_size( ‘large-size’, $LARGE_SIZE, 9999 ); EDIT #1: Try to add this filter to delete the original image: add_filter(‘wp_generate_attachment_metadata’, ‘delete_fullsize_image’); function delete_fullsize_image($metadata) { $upload_dir = … Read more

Show current page featured image in sidebar

I’m assuming you’re going to be outputting this on a singular page (Post, Page, Attachment)? If so, the easiest thing to do is to put your post AND sidebar content inside the Loop, so that you have access to the $post global, and post-related template tags. Alternately, you could define a variable, inside the Loop, … Read more

How to get custom image sizes into media uploader dropdown?

Try seperating it like this: function setup_image_sizes() { if ( function_exists( ‘add_image_size’ ) ) { add_image_size( ‘post-image’, 608, 350, true ); } } add_action( ‘after_setup_theme’, ‘setup_image_sizes’ ); function post_image_sizes($sizes){ $custom_sizes = array( ‘post-image’ => ‘Post Image’ ); return array_merge( $sizes, $custom_sizes ); } add_filter(‘image_size_names_choose’, ‘post_image_sizes’); That way it is working in my setup. Additional Sources: … Read more

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

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)