Hot answers tagged

16

Came here as this post is among the top hits on the search engine when looking for WordPress image alt and title. Being rather surprised that none of the answers seem to provide a simple solution matching the question's title I'll drop what I came up with in the end hoping it helps future readers. // An attachment/image ID is all that's needed to retrieve ...


7

I found the culprit! WordPress 5.3 introduced additional image sizes which can be found via /wp-includes/media.php. Updating my function, like so, removed the extra sizes: function remove_default_image_sizes( $sizes) { unset( $sizes['large']); // Added to remove 1024 unset( $sizes['thumbnail']); unset( $sizes['medium']); unset( $sizes['...


3

This behaviour was newly introduced by WordPress with version 5.3 (released on 12th of November 2019). So if you updated to that version, WP is behaving according to design. The announcement post for the new version only mentions it as including improved large image support for uploading non-optimized, high-resolution pictures in the section "Block ...


3

Ignoring our off-topic request for a plugin, the good news is: yes, this is possible. On the other hand, it is quite some work, so I will give just an outline here. WordPress does have built-in image manipulation. The default one is Image Magick. WordPress' image editor class, however, only offers a subset of what Image Magick is actually capable of. This ...


2

(this should be a comment, but my reputation is too low) Setting jpeg_quality will not disable compression because it does not disable processing. JPEGs will be always compressed, and they are almost never lossless, not even at 100 - it does not stand for "100% original quality". What happens here, is that WordPress's default image processing does not ...


2

A simple and effective approach const editor = wp.data.select('core/editor'); const imageId = editor.getEditedPostAttribute('featured_media'); const imageObj = wp.data.select('core').getMedia(imageId); ImageObj gives you a reasonable amount of image data to work with.


2

I couldn't find a way to place an image tag in there, so I did as Tom J Nowell suggested. I added a class and using CSS I made the text disappear and have the logo image appear in its place. It seems to work fine.


2

I think what you're looking for is the filter: wp_handle_upload_prefilter. From the Codex: The single parameter, $file, represent a single element of the $_FILES array. The wp_handle_upload_prefilter provides you with an opportunity to examine or alter the filename before the file is moved to its final location. Example code from the Codex: ...


2

Running the wp media regenerate command from WP-CLI with the --only-missing argument is quite fast (takes about 30 seconds for 4000 images) and rebuilds _wp_attachment_metadata correctly: wp media regenerate --only-missing


2

You can use REST API to retrieve media item. Just send GET request to this address (change example.com to your site): http://example.com/wp-json/wp/v2/media/<id> If you pass correct ID, then you'll get all info regarding that media file. For example I get something like this for one of my image files: { "id": 546, "date": "2019-01-23T11:22:15", ...


2

I am assuming you want this value on the front-end as opposed to needing it in the block editor due to the <figure> somehow not displaying correctly when viewed in the block editor. If that is the case then you can use something similar to DOMDocument as per the following example: Assume HTML of: <div> <figure> <img src="...


2

Obviously, I imagine you already checked cron jobs. No one can tell you, but whenever you have an issue and you're wondering "what the hell is interacting with my system?" and that part that's problematic (in your case, the deletion of the image) has actions inside of it, we can see what called that specific deletion. So let's see how this applies in your ...


2

The "All Posts" page - /wp-admin/edit.php - does not show a featured image just by using WP Core. You have to add code to display featured images there. You may need to look back at your backups to see what code you were previously using to get the featured image to show up. It could be that you edited your theme's functions.php file, and when you updated ...


2

You can check mime type of uploaded image before upload to media. Add mimeTypes in $allowmimeType which you want to allow. then check uploaded files mimetype $fileMimeType. If not found in allowed mimetype then return false. // Insert Attachment function insert_attachment($file_handler, $post_id, $setthumb='false') { if ($_FILES[$file_handler]['error'] ...


2

If you're trying to link the image to the page in the post editor you can click on the image and then click the link icon to set the target. You can do the same thing in HTML (in the editor in source view), in a plugin, or in a theme like this: <a href="/link/to/your/page"> <img src="/link/to/your/image" /> </a>


2

It turned out that the method called strip_tags(preg_replace(" (\[.*?\])", '', $output)) before strip_shortcodes($output), which caused aforementioned issue, since the code removed shortcode in square brackets, but retained contained image captions. I could fix it by swapping the two method calls like this: $output = get_the_content(); $output = ...


1

my final code that worked quiet brilliant $va_category_HTML .='<li '.$carrentActiveClass.'><a href="' . esc_url( $term_link ) . '">' . $term->name . '</a>'; $icon = get_field('firma_image', $term->taxonomy . '_' . $term->term_id); $va_category_HTML .= sprintf('<img src="%s" />',...


1

Unfortunately, it looks like the code that runs your widget will not let you add your image: The code here shows that a loop is creating the unordered list and there are no filters where you can inject your own image. You can add your own code to the plugin, but it's not recommended as once you push an update it will break. You may also be able to add some ...


1

Image Hotspot by DevVN and Interactive Maps might have what you're looking for!


1

You're not outputting any attributes besides the src and class. Try using the_post_thumbnail() instead. <?php the_post_thumbnail( 'post-thumbnail', array( 'class' => 'img-responsive' ) ); ?> This will include all attributes and supports responsive image markup by default.


1

You're onto the answer... The function, wp_get_attachment_url() (see Codex) just gives you the URL. You could wrap it in a link: echo '<tr><td><a href="' . esc_attr(wp_get_attachment_url($row['item_code1'])) . '">' . esc_html($item_1_title) . '</a></td></tr>'; Alternately, you can use wp_get_attachment_link() (see Codex)...


1

This is a very good question. The answer to the referenced post requires a change to the WP options. They are stored in the database in the wp_options table (assuming wp_ is your prefix). There are a few ways to change these in this case: Direct DB access: if you're comfortable modifying the WP DB directly (and you have access) you can add a record to the ...


1

I think you have already discovered the problem with a plugin approach. They will look for unlinked media (images not associated with a post) and remove those files. As you have said, you are using custom fields and you may also have uploaded images inside your post content. Sadly the only option I can think of is to use a find command to get a list of all ...


1

You can try using the function get_attached_media() like this: add_action( 'before_delete_post', 'wps_remove_attachment_with_post', 10 ); function wps_remove_attachment_with_post( $post_id ) { /** @var WP_Post[] $images */ $images = get_attached_media( 'image', $post_id ); foreach ( $images as $image ) { wp_delete_attachment( $image-&...


1

That's HUGE! I have good news. WordPress handles creating image thumbnails. You can add new sizes or use the thumb/medium/large sizes that are baked in. You just have to call wp_get_attachment_image() with the image size as long as the image are in the media library. Want to add a new image size for a thumbnail? Call add_image_size() with the width/...


1

You might be facing this problem because your theme does not support featured images. But you can easily add that support, so no worries :) To quote the WordPress Theme Handbook: Themes must declare support for the Featured Image function before the Featured Image interface will appear on the Edit screen. Support is declared by putting the following ...


1

You will most likely want to use filters. The main issue is that developers will need to make sure to use the correct functions like "the_post_thumbnail()" etc. You can use wp_get_attachment_url https://codex.wordpress.org/Function_Reference/wp_get_attachment_url I use this when doing local development, but want all my local images to load from the ...


1

Emoji are just letters. They're defined by the user's operating system. The same way the alphabet is. You don't need to do anything special. If you did, then that website would be pointless. The only thing you need to consider is older operating systems that don't support Emoji, but WordPress itself loads a script that enables Emoji for those operating ...


1

You should just be able to use the HTML5 download attribute for that. So just make your links look like this: <a href="<?php echo wp_get_attachment_image_url($id); ?>" download>Download Image</a> where $id is the attachment ID


1

WooCommerce itself registers support for the default themes. For Twenty Fifteen it registers the following: add_theme_support( 'wc-product-gallery-zoom' ); add_theme_support( 'wc-product-gallery-lightbox' ); add_theme_support( 'wc-product-gallery-slider' ); add_theme_support( 'woocommerce', array( 'thumbnail_image_width' => 200, '...


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