wp_get_attachment_url with specific image_size?

You can use single_product_large_thumbnail_size Woocommerce filter as shown in following code to apply custom image size for product. In the above code replace this apply_filters( ‘single_product_large_thumbnail_size’, ‘shop_single’ ) with this apply_filters( ‘single_product_large_thumbnail_size’, ‘custom_thumbnail_size’ );

PHP code to call image Caption, Alternative Text, and Decription?

WordPress stores image (attachment) data as follows: Description: post_content field Caption: post_excerpt field Alt: _wp_attachment_image_alt meta value And in code, that translates to: // Description echo $post->post_content; // Raw the_content(); // Caption (description as fallback) the_excerpt(); // Caption (explicitly) echo $post->post_excerpt; // Raw if ( has_excerpt() ) { the_excerpt(); } // Alt echo get_post_meta( $post->ID, … Read more

How to change the target size of images clicked on in WordPress standard gallery

I came across a solution for your functions.php from the following site that looks like it will do the trick. More detail on the implementation here: http://oikos.org.uk/2011/09/tech-notes-using-resized-images-in-wordpress-galleries-and-lightboxes/ Snippet below: function oikos_get_attachment_link_filter( $content, $post_id, $size, $permalink ) { // Only do this if we’re getting the file URL if (! $permalink) { // This returns an … Read more

Automatically add image caption with values from a post parent field?

In the filter, you will need to find the post parent of $post, get the value of the custom field of parent post and then add that value to $post[‘post_excerpt’] (where the caption is stored): add_filter(‘attachment_fields_to_save’, ‘wpse_insert_custom_caption’, 10, 2); function insert_custom_default_caption($post, $attachment) { //Check if the $post is attached to a parent post if( $post->post_parent … Read more

Custom image sizes without add_image_size()

Docs, docBlocks and Codex … Basically you have a very simple mistake: The $attributes array is the 2nd argument: function the_post_thumbnail( $size=”post-thumbnail”, $attr=”” ) { echo get_the_post_thumbnail( null, $size, $attr ); } How it works internally 1) The HTML itself gets built by wp_get_attachment_image(). 2) Later on, inside this function, the next relevant function call … Read more

How to get media objects

Have you tried to use get_children() function? Edit: All media attached to any post is treated as children of it. The function wp_get_attachment_image() will only return images. With the function get_children() you’ll be able to get all the media, images or anything else. In the above link, you can find some examples.

wordpress media library shows empty images

Plugins such as Search and Replace can help you to properly fix the URLs in your database. Likewise, consider using backup-and-migration plugins such as BackupBuddy (paid) or Duplicator (free) to properly and more easily move your site (while automatically handling the above search-and-replace operation).

Featured images get shrunken

Hey if you want to add custom image size then add the following code in your function.php file add_image_size( ‘thumb’, 220, 180, true ); and then call featured image in your template like this <?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it. the_post_thumbnail(‘thumb’); } ?> … Read more