Shortcode for a link and thumbnail

You are assigning the attachment URL to your $url variable: $url = wp_get_attachment_url( get_post_thumbnail_id( $id ) ); then passing that same variable back to wp_get_attachment_url: return ‘<img src=”‘ . wp_get_attachment_url( $url ) . ‘”/><a href=”‘ . get_permalink( $id ) . ‘”>’ . get_the_title( $id ) . ‘</a>’; You should simply output it instead: return ‘<img … Read more

Get meta data from image

Image data is stored as if it were a post, or a CPT, so you can treat it like one. $album_id = get_the_id(); $img = new WP_Query(array(‘p’=>$album_id,’post_type’=>’attachment’)); var_dump($img->posts[0]->post_content); Or, a little more complicated,… $album_id = get_the_id(); $img = new WP_Query(array(‘p’=>$album_id,’post_type’=>’attachment’)); if (!empty($img->posts[0])) { var_dump($img->posts[0]->post_content); } get_the_ID will return the ID of the current post so … Read more

Image resize using url parmater

WordPress(.org) doesn’t have anything like this built into the core. A lot of theme developers use Timthumb to achieve that. The example you’ve linked to is on a wordpress.com server so there will be something custom going on for that functionality. You could also look at the WordPress functions add_image_size & the_post_thumbnail.

Customize WooCommerce Product Images (Placement and size) [closed]

The file responsible for generating the sidebar cart is mini-cart.php and is located in woocommerce/templates/cart/mini-cart.php What you do is you copy that file and paste it into YOURTHEMEFOLDER/woocommerce/cart/mini-cart.php Open up that file and edit line 40 where it contains <?php echo $_product->get_image(); ?>` Change that to <?php echo $_product->get_image( array( 50, 80 ) ); ?> … Read more

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