How do I intercept and modify the functionality of wp_get_attachment_image()?

It might be a solution to string replace /wp-content/uploads with ” (empty) like for an example: Lets say: wp_get_attachment_image() returns=”/wp-content/uploads/myimage.png”; <?php echo str_replace(‘/wp-content/uploads/’, ”, wp_get_attachment_image()); ?> This will result in echo: ‘myimage.png’ Try this: function alter_image_src($attr) { $attr[‘src’] = str_replace(‘/wp-content/uploads/’, ”, $attr[‘src’]); return $attr; } add_filter( ‘wp_get_attachment_image_attributes’, ‘alter_image_src’); In your functions page (of theme).

Allow SVG in WP step by step

But how to know what is my WP namespace? namespacing a function, in WP land, just means prefixing it with something that makes it more unique and unlikely to conflict with anything else. Generally that means you do both a “vendor” and a “package”. For instance, if I’m building a plugin, my function upload mimes … Read more

big trouble with javascript

Relative URLs work nicely in wordpress, which is the reason for your failures. In general never use relative URLs for resources as they will most likely fail when a site is using “pretty permalinks”. Best thing for what you are doing is to “group” the graphical resources and styling in a CSS (in which resources … Read more

Force square image crop during upload?

Your assumption that all images are uploaded from a browser is false. Currently images can be uploaded via the XML-RPC protocol and once the REST API will be merged it will also be used to upload images. Images can also be imported from other sites. The point is that you should not assume that images … Read more

How to test if there are no more previous or next image on attachment page?

You need to use the adjacent image link filters, defined in the source of adjacent_image_link() function. Example: add_filter( “next_image_link”, “cyb_next_image_link”, 10, 4 ); function cyb_next_image_link( $output, $attachment_id, $size, $text ) { if( $output == ” ) { return ‘<div class=”next-image”><span>NEXT</span> <i class=”fa fa-angle-right”></i></div>’; } return $output; } add_filter( “previous_image_link”, “cyb_previous_image_link”, 10, 4 ); function cyb_previous_image_link( … Read more

Large image not showing dimensions in Media Library

I see this happen when WP runs out of memory or time while processing large images. The image resizing, including setting the attachment custom fields for the dimensions, doesn’t complete. It can be the image dimensions (uncompressed file size really) rather than jpeg file size that are the problem, as the image is decompressed into … Read more

Dynamically determine the width and height of a image file to be cropped & uploaded AFTER form submission given fixed aspect ratio

Here is my resolution: Download and unzip JCrop and unzip jquery.Jcrop.min.js & jquery.Jcrop.css to the js & css sub-directory respectively under the theme template directory. Place the following code in header.php just before </head> (you need to comment out the first line if you’ve already include the jquery.min.js in the other place): <script src=”https://wordpress.stackexchange.com/questions/209358/<?php echo … Read more

Can’t get text to wrap around image

WordPress provides a few generated classes just for this issue. What you probably want is to float the image left in your example. The CSS rules listed in the Generated Classes section of this Codex page are what you are after. https://codex.wordpress.org/CSS#WordPress_Generated_Classes For the sake of future-proofing or a URL change, here is that content: … Read more

Save Image in wp_options-Table

After some time I found out how to solve my Problem. In short, I have to use Javascript to open the WP-Media Uploader. And in my options I only save the attachment ID. Here is my code: HTML / PHP: <?php $options = get_option( ‘mysettings’ ); $image_id = esc_attr__( $options[‘image_id’]); ?> <div id=”logo”> <?php $hasImage … Read more