Hot answers tagged

2

I stumbled on a good and more global solution for this on Isabel Castillo's blog, by using wp_get_attachment_image_attributes filter: function isa_add_img_title( $attr, $attachment = null ) { $attr['title'] = trim( strip_tags( $attachment->post_title ) ); return $attr; } add_filter( 'wp_get_attachment_image_attributes','isa_add_img_title', 10, 2 )...


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>', esc_html( $caption ) ); ...


1

If $size is already an array in your original code as it looks to be, then the argument passed will become array(array(150,150)) instead of just array(150,150) and fail, so you can just do: <?php $title=get_the_title(); the_post_thumbnail( $size, array( 'alt' =>$title) ); ?>


1

What am i missing? 'tag' may be a valid argument for get_posts() via WP_Query, but requires the tag slug in that case. Try using 'tag_id' instead. get_posts() apparently enables 'category', but expects the the ID, even though in WP_Query the same argument is 'cat' (vs. 'category_name', et al). A little confusing, perhaps, altogether. I know it still ...


1

I couldn't find any WP specific event to hook in to. What you can do is set up an observer with a callback to respond to DOM changes using MutationObserver and check if the your featured image has been added in the callback. There's no support in IE < 11 though, which may be a deal breaker for you, or maybe not. I've done minimal testing on this, but it ...


1

Very broad solution. There are two problems you are facing there are different HTML generated by the server based on if there is a featured image Meta box are just a UI artifact of post editing and are not easily manipulated via AJAX (even in AJAX it is easier to handle full objects rather then their individual properties, even if only for keeping ...



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