Tag Info

Hot answers tagged

3

Actually WordPress reduce quality of image when you upload it via media uploader. WordPress has built in compression for JPG images. Whenever you upload an JPG/JPEG image to WordPress media library, WordPress will automatically compress your images to 90% of the original quality, this is intended to help your pages load faster and keep file sizes smaller. ...


1

If you know the image's ID : wp_get_attachment_image( $image->ID, array(200, 112) ); returns an HTML img element or empty string on failure. The entire code could be something like : <a href="<?= get_attachment_link( '5435' ); ?>"> <?= wp_get_attachment_image( '5435', array(200, 112) ); ?> </a>


1

By using wp_get_attachment_image_src() function get the original url of thumbnail if ( has_post_thumbnail() ) { $image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); $image = $image_url[0]; } Then add Image Url to your custom code <a href="<?php echo $image; ?>"><img class="alignright size-medium ...


1

All of the code in your question can be replaced with: require_once( ABSPATH . 'wp-admin/includes/image.php' ); require_once( ABSPATH . 'wp-admin/includes/file.php' ); require_once( ABSPATH . 'wp-admin/includes/media.php' ); if ( $_FILES ) { foreach ($_FILES as $file => $array) { $image_post_id = media_handler_upload( $file ); if ( is_wp_error( ...


1

Just use the public API functions: has_shortcode( $content, $tag );. It uses shortcode_exists( $shortcode ); internally to search the global $shortcode_tags array for the shortcode you are searching for. If that is successful, it uses get_shortcode_regex() to search for the actual shortcode - this will save you quite some time and avoid mistakes. ...


1

Instead of your code for image, use this following. <?php $thumb_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 120, 90, true ); ?> <img src="<?php echo $thumb_image[0]; ?>" alt="<?php echo esc_html( get_the_title() ); ?>" width="<?php echo $thumb_image[1]; ?>" height="<?php echo $thumb_image[2]; ...



Only top voted, non community-wiki answers of a minimum length are eligible