New answers tagged

0

You don't need php at all to achieve what you are after. This can be done with just css. This shows the title and excerpt by default. .wrap .wp-tiles-byline-fade-in .wp-tiles-tile-with-image .wp-tiles-byline { opacity: 1; } This hides the excerpt again now that we have revealed it. .wrap .wp-tiles-byline-fade-in .wp-tiles-tile-with-image .wp-tiles-...


0

I am proud to announce that I have found the solution thanks to @cjbj good advice. I paste the code here. I know it will help others. In addition, I used the function preg_quote to protect the path to the image. protected_path = preg_quote($filename); This code works great. // $filename should be the path to a file in the upload directory. $...


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) ); ?>


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 )...


0

I'd say register a custom post type, eg. cat_image, so the images can be uploaded to a post using the existing featured image metabox. You could sync the data using wp_insert_post matching the widget ID to the custom post slug..? // to match widget to an existing custom post // similar to get_post but can use slug (if no post parents) $slug = $instance['id'...


0

The easiest way to achieve this is to use the Multiple Post Thumbnails plugin. Once you have done this, add the following snippet to your functions file: if (class_exists('MultiPostThumbnails')) { new MultiPostThumbnails(array( 'label' => __('Secondary Featured Image', 'yourtextdomain') 'id' => 'secondary-image', 'post_type' => '...


0

I created a solution through trial and error, unfortunately having to resort to custom fields. I added a custom field to every child element i wanted to display and used the code: <?php $args = array( 'post_type' => 'page', 'meta_key' => 'xxxx', 'meta_value' => 'xxxx' ); $myPages = new WP_Query($args); while (...


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 ...


0

The most elegant way is to use wp media regenerate. From the example: # re-generate all thumbnails, without confirmation wp media regenerate --yes


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 ...


0

You don't give enough details but your image naming is just bad for wordpress. I am not sure if anywhere in core there is code that tries to detect a resolution by the filename suffix but it is a fragile and confusing habit. If you have to have the data in the name maybe use underscore instead.


0

The theme was auto generating alternative image sizes for responsiveness, so my newly named images were actually duplicates. Leaving this up in case anyone makes same mistake and stumbles across this.



Top 50 recent answers are included