wp_get_attachment_image_src and server path

WordPress doesn’t store path of generated sizes anywhere, you need to build it. As suggested by @kraftner in comments, wp_get_attachment_metadata() can be used to obtain some of the pieces you need to build the path. An alternative is image_get_intermediate_size(). The missing piece is the absolute path of upload folder. In theory, that can be retrieved … Read more

How to reference a theme image in a stylesheet?

It depends on your image and stylesheet location. But this is the syntax: .theme-image { background-image: url(‘../images/header-img.jpg’); } The above code is for the structure wp-content – themes – your-theme – images – header-img.jpg – css – style.css You are making the browser come one directory before and search for images directory.

Get attachment/image info in JS

Long story short, you can get info about an attachment by using wp.media.attachment() function. This will give you complete data as long as this attachment is already loaded by another script or an wp.media() popup. If the data is not yet loaded, you can load it using .fetch() method on attachment, which works because it … Read more

Is it possible to “freeze” a WordPress blog?

Take a look at this WordPress plugin WP Static HTML output This plugin produces a static HTML version of your wordpress install, incredibly useful for anyone who would like the publishing power of wordpress but whose webhost doesn’t allow dynamic PHP driven sites – such as MobileMe. You can run your development site on a … Read more

Watermarking Images with WordPress with WP_Image_Editor

If you really want to use these classes the only way would be to extend both existing implementations Wp_Image_Editor_Imagick and Wp_Image_Editor_GD. Here’s an approach for the Wp_Image_Editor_GD: namespace WPSE98156; use Wp_Image_Editor_Gd, Wp_Error; class WatermarkImageEditor extends Wp_Image_Editor_Gd { /* * @param resource $stamp (A GD image resource) * * @return bool|WP_Error */ public function stamp_watermark( $stamp … Read more

Is there a simple way to just insert a link to an image (without inserting an image)?

I found a solution based on the code of this page: https://core.trac.wordpress.org/ticket/22180 All attachment files have a post status of ‘inherit’. So first you need to add “inherit” as one of the possible post status to search for. You can use the wp_link_query_args filter to do that. function my_wp_link_query_args( $query ) { if (is_admin()){ $query[‘post_status’] … Read more