Caption in Page adding unwanted 10px to width

Here’s what you can do. There’s a filter at the beginning of the shortcode execution function for the front end that will let you hijack the captions. Returning a non-empty value will stop execution of the shortcode, so if you just process the shortcode the way you want it to be processed and return that … Read more

WordPress function: limit size, only jpg, jpeg, limit of uploaded files per account

You cannot check the image before uploading, as WordPress is a serverside script. However, before inserting the image in the Media library, you have different options, as I explained in this answer, with filtering wp_handle_upload_prefilter. In your case, the function filtering the wp_handle_upload_prefilter would be something like this: add_filter(‘wp_handle_upload_prefilter’, ‘f711_image_size_prevent’); function f711_image_size_prevent($file) { // get … Read more

How to display a shortcode caption somewhere other than the_content

Try this: $caption_info = array(); add_filter( ‘img_caption_shortcode’, ‘capture_caption’, 10, 3 ); function capture_caption( $blank = ”, $attr, $content ) { global $caption_info; $caption_info[] = array(‘attr’ => $attr, ‘content’ => $content ); return ‘ ‘; } It will save info from all captions into global $caption_info variable and suppress their display in content (space is returned … Read more

Making images from single.php pointing to an attachment .php template

If I understand you correctly, you need to link your images not to the file, but to the attachment template (attachment.php). If so, then try the following code in your single.php: <?php if( has_post_thumbnail() ) { $attachment_page_url=””; $attachment_page_url = get_attachment_link( get_post_thumbnail_id() ); ?> <a href=”<?php echo $attachment_page_url; ?>” class=”featured-image”> <?php the_post_thumbnail(); ?> </a> <?php } … Read more

Display thumbnail from custom field

can you explain why do you need custom fields ? (personally i think they are HUGELY over-used.. especially for images ) if there is no specific reason why you need it , you could use the the_post_thumbnail(); function . like so : the_post_thumbnail(‘thumbnail’); // Thumbnail (default 150px x 150px max) the_post_thumbnail(‘medium’); // Medium resolution (default … Read more

How to get current image’s slug in WP_image_editor?

Try adding this to functions.php: add_filter(“wp_image_editors”, “my_wp_image_editors”); function my_wp_image_editors($editors) { array_unshift($editors, “WP_Image_Editor_Custom”); return $editors; } // Include the existing classes first in order to extend them. require_once ABSPATH . WPINC . “/class-wp-image-editor.php”; require_once ABSPATH . WPINC . “/class-wp-image-editor-gd.php”; class WP_Image_Editor_Custom extends WP_Image_Editor_GD { public function generate_filename($suffix = null, $dest_path = null, $extension = null) { … Read more

Circumventing the normal image upload process

If the question is “Why don’t my images load?” the answer is “Don’t use relative URLs in a WordPress context.” Use functions like admin_url and these other related functions instead. Relative URLs are relative to the URL of the page you are on, and are calculated by the browser. In other words, relative URLs are … Read more