How to get cropped thumbnail source for custom post type

You should add your custom image size with this code: add_image_size( ‘my-test-image-size’, 148, 148, true ); Then in your template file you can get cropped image using wp_get_attachment_image_src like this: $attachment_id = …; // i.e. get_post_thumbnail_id() $image_info = wp_get_attachment_image_src($attachment_id, ‘my-test-image-size’); echo ‘<img src=”‘. $image_info[0] .'” … />’; // $image_info[0] contains url of cropped image To … Read more

How to link to featured image to media file URL

You would need to edit your themes single.php template file and modify the line of code calling the featured image. It would look something like this: <?php the_post_thumbnail(); ?> Replace it with this… <?php if ( has_post_thumbnail()) { $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), ‘large’); echo ‘<a class=”lightboxclassname” href=”‘ . $large_image_url[0] . ‘” title=”‘ . the_title_attribute(‘echo=0’) . … Read more

Image thumbnails not available post migration, but still accessible via direct URL – DB issue

Domain change This kind of error may be caused by wrong host name in image urls that are stored in the database. It is necessary to replace strings holding your old domain with new one: http://olddomain.com –> http://newdomain.com In every migtration process I use the following recommended tool: https://interconnectit.com/products/search-and-replace-for-wordpress-databases/ Upload it to your WP root … Read more

How to move image thumbnails into custom folder for custom post type

Use bellow filter in the functions.php <?php add_filter( ‘upload_dir’, function($args) { if( !isset($_REQUEST[‘post_id’]) ) { return $args; } $post_type_name = get_post_type( $_REQUEST[‘post_id’] ); if( $post_type_name=”custom_post_type” ) { // Set the new path depends on current post_type $newdir=”https://wordpress.stackexchange.com/” . $post_type_name; $args[‘path’] = str_replace( $args[‘subdir’], ”, $args[‘path’] ); //remove default subdir $args[‘url’] = str_replace( $args[‘subdir’], ”, $args[‘url’] … Read more

If I Regenerate Thumbnails, would WordPress delete the existing Thumbnails and replace them with ‘new copies’?

Here’s what you can do: Delete the Old Thumbnails Download and install the Thumbnail Cleaner plugin. This plugin will delete all of your current thumbnails. You can do this manually by writing a PHP snippet that detects thumbnails and deletes them, but it’s not really that necessary. Resize the Original Images Once you have deleted … Read more

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