Hot answers tagged

3

Register a collection post type to represent a single collection. You'll get permalinks and rewrite rules to resolve the requests for free. Insert a new collection post for a user when they create a collection, and save the chosen post IDs as an array in post meta. You can pass that array directly as post__in argument in a WP_Query instance to load the ...


2

It's already in the docs. Try this: <?php $image = get_field('image'); if( !empty($image) ): ?> <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /> <?php endif; ?> For easier debugging, try this: var_dump($image); to print out the $image variable to know what is in $image. You can also put ...


2

shutter speed is one of the exif data wordpress tries to extract from images when uploaded. If the image do not contain the info it will be zero, hence your division by zero error. Somewhere before that code you should check if the image even needs to go there. If it is not a photo then probably not.


2

In general I wouldn't recommend modifying the original uploaded image files, just in case we might need to re-generate intermediate sizes. But let's see if it's possible :-) We can in general let WordPress choose the image editor, that depends on modules like GD or Imagick, through: $editor = wp_get_image_editor( $file ); but this can return an WP_Error ...


2

I can already tell that you're using ACF - if you don't want to change the return settings for the field, you can bypass ACF and just pull the image ID directly from post meta: $image_url = get_field( 'my_field_name' ); $image_id = get_post_meta( $post->ID, 'my_field_name', true ); $image_meta = wp_get_attachment_metadata( $image_id );


1

Your first function get_images_from_media_library() only returns images guid, I'd suggest to extend it by returning all image datas : function get_images_from_media_library() { $args = array( 'post_type' => 'attachment', 'post_mime_type' =>'image', 'post_status' => 'inherit', 'posts_per_page' => 6, ...


1

Unfortunately @Patrick's answer breaks the srcset functions introduced in WP 4.4. Fortunately, we just need to add two additional functions! First, we need to temporarily re-introduce all of the registered thumbnail sizes to the image metadata so they can be considered: function bi_wp_calculate_image_srcset_meta($image_meta, $size_array, $image_src, ...


1

I see multiple messages about images and some script blocked in Chrome with (blocked:mixed-content) reason. Which basically means it doesn't like unsecure http resources in secure https site. WordPress doesn't handle this particularly well. It is designed to use absolute URLs and they tend to end up hardcoded in content and such. You would have to: ...


1

The WP_Query class can match IDs as well as search terms. An idea would be to use the pre_get_posts action to detect if the search term is numeric and, if it is, set the query to work with attachments while passing the search as the ID. function wpse223307_allow_search_by_attachment_id( $query ) { //Only alter the query if we are in a search screen,... ...


1

From the Dashboard of your WordPress website, go to Media > Library You will see all of your images there. Select the image which one you want to update, and click "Edit". The "Edit Media" page will open. Scroll down to the bottom of this page, you will be found few input boxes to provide the Caption, Alternative Text and the Description of your image ...


1

I just worked out why it wasn't working. In order for WordPress to generate the srcset and size attributes for images in the_content, it must have a class associated with it indicating the image attachment id (for example, 'wp-image-41'). This is automatically attached to the image when it is inserted via the editor. Unfortunately, in my older posts, all ...


1

The problem is that you are using functions from GD library to manipulate images, not functions from WordPress Image API (WP_Image_Editor class). So, WordPress things doesn't apply to the generated image by your code. WordPress Image API uses ImageMagick if available, otherwise it uses GD library. In order to keep EXIF data: If GD library is used, you ...



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