wp_get_attachment_image_src on multisite

wp_get_attachment_image_src() function returns an array that’s why your code isn’t working. Try the following code. <a href=”https://wordpress.stackexchange.com/questions/295180/<?php echo esc_url( home_url(“https://wordpress.stackexchange.com/” ) ); ?>” rel=”home”> <?php if ( get_theme_mod( ‘bwpy_logo2’ ) ) : $img_data = wp_get_attachment_image_src( absint( get_theme_mod( ‘bwpy_logo2’ ) ) ); $img_url = isset( $img_data[0] ) ? $img_data[0] : ”; // Or you can try … Read more

Way to store featured image width and height in two separate variables?

You can always use the wp_get_additional_image_sizes() function to retrieve an image “size” (i.e. width, height, and the ‘crop’ option), like this: $image_sizes = wp_get_additional_image_sizes(); if ( isset( $image_sizes[‘slide_image’] ) ) { $size = $image_sizes[‘slide_image’]; var_dump( $size ); // Demo echo $size[‘width’]; // Demo } UPDATE In reply to your comment, i want to get the … Read more

How to know what size image to use for background? [closed]

Short Answer : Any Detailed Answer : The Sydney theme for WordPress is a very unique and responsive theme. When you upload an image for background then it will automatically be adjusted. But if you really want to add a image of specific dimensions, then 2560*1600 size is best.

Why WordPress strips scr string from img tag off?

Because the correct attribute is src. S.R.C, not S.C.R. (I’d have assumed it was a typo in the question, but you used it 3 times). The WordPress editor removes attributes that aren’t whitelisted, and since scr isn’t an actual attribute it’s not on the whitelist.

Change Responsive Images Maximum Width of 1600px

You can simply remove that limit, go to your functions.php and add this code. function remove_max_srcset_image_width( $max_width ) { return false; } add_filter( ‘max_srcset_image_width’, ‘remove_max_srcset_image_width’ ); If you want to increase, go to your functions.php and add this code. function custom_max_srcset_image_width( $max_width, $size_array ) { $max_width = 1800; return $max_width; } add_filter( ‘max_srcset_image_width’, ‘custom_max_srcset_image_width’);

Get image url using image id

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”, “date_gmt”: … Read more

Remove Featured Image & All Media Uploaded to the Post

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->ID, true ); } } Note that this will permanently delete all the image files related to … Read more

Image editor is not loading

Found the issue Checking in the related solutions I found this one WordPress Image Editor not working – conflict? They were talking about a missing ?>, but obviously this was not related because I was using the default theme and not plugins. But suddenly remembered that I created a simple mu-plugin 10 days ago, and … Read more

Add clickable link on an image

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=”https://wordpress.stackexchange.com/link/to/your/page”> … Read more