Hot answers tagged

3

As far as I know you could hook into the filter image_send_to_editor like this: function html5_insert_image($html, $id, $caption, $title, $align, $url) { $url = wp_get_attachment_url($id); $html5 = "<figure id='post-$id media-$id' class='align-$align'>"; $html5 .= "<img src='$url' alt='$title' />"; $html5 .= "</figure>"; return $...


2

There's a filter called image_send_to_editor that lets you specify the markup. You will also need wp_get_attachment_metadata to retrieve width and height. It is called like this (untested): add_filter( 'image_send_to_editor', 'wpse_231693_img_markup', 10, 7 ); function wpse_231693_img_markup ($html, $id, $alt, $title, $align, $url, $size ) { $...


2

Is there are better way to change this (annoying) variable please? The Twenty Sixteen theme provides you with the twentysixteen_content_width filter, where the default is 840. To modify it you should be able to use this within your child theme's functions.php file: add_filter( 'twentysixteen_content_width', function( $content_width ) { // Override ...


1

Suppose you haven't modified anything to change the default content output, maybe this can help: add_filter('the_content', function($content) { $content = preg_replace('~^<p><img([^>]+)></p>~i', '', $content, 1); return $content; }, PHP_INT_MAX);


1

The filter you are using only stops jpeg compression. This does not prevent quality loss when resizing an image. Manually you would apply a sharpen filter afterwards to regain some crispyness in the image. WordPress doesn't do that. However, WP does have the WP_Image_Editor class for image manipulation. It has some built-in methods, such as resize and ...


1

This is mostly a PHP general question about concatenating a function's returned value with a (or many) string(s). The get_bloginfo function returns a string instead of echoing it directly. Thus you start off with: // First param value: stylesheet_directory // Using "template_url" also works unless you are using a child theme // In that case, "template_url"...


1

Here's one way to inject the custom field as the featured image caption with help of the post_thumbnail_html filter: add_filter( 'post_thumbnail_html', function( $html, $post_id ) { if( $html && $caption = get_post_meta( $post_id, 'wpcf-bildunterschrift', true ) ) $html .= sprintf( '<p>%s</p>', sanitize_text_field( $caption ) ...


1

The answer is to use WP's responsive images, customising the sizes attribute to suit your use case. Reading between the lines, I'm assuming here that you are using a responsive design approach to show the different layouts at different widths. The easiest way is to start by making yourself a replacement template tag function for the_post_thumbnail: ...


1

I am using standard WP galleries and have each image link to an attachment page where the image is displayed fullsize. To show PREVIOUS and NEXT links in order for the user to get to the corresponding images I found the functions previous_image_link and next_image_link useful. In my attachment.php I have the following lines to make WordPress display ...


1

Since 3.7 there is a filter to change the width of the wrapping div directly. This will fix the extra 10px, and won't let the caption extend past the width of the image (unlike width: auto !important). function wp456_img_caption_width( $width, $atts, $content){ //by default 10 is added if image caption return $width - 10; } add_filter( '...



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