Featured image shortcode

Register the shortcode, ideally in a plugin or functions.php if you have to. add_shortcode(‘thumbnail’, ‘thumbnail_in_content’); function thumbnail_in_content($atts) { global $post; return get_the_post_thumbnail($post->ID); } Add the shortcode to you post content. [thumbnail] If you want more features, see this post or the pastebin. ADDING CAPTIONS AND LINKS add_shortcode(‘thumbnail’, ‘thumbnail_with_caption_shortcode’); function thumbnail_with_caption_shortcode($atts) { global $post; // Image … Read more

Separate Media Library for each user

Built in features The Media Library has major updates with the upcoming version. You can see the changes in the slides by Daryl Koopersmith here. You can read the announcement and discussion on “Make”. Your request for “tags/categories” is already built into 3.5. Note The difference between themes and plugins is pretty easy: Display vs. … Read more

How to display a page’s featured image?

Adapted from this thread on the WP forums: <?php if (has_post_thumbnail( $post->ID ) ): ?> <?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), ‘single-post-thumbnail’); ?> <style> #banner-id { background-image: url(‘<?php echo $image[0]; ?>’); } </style> <?php endif; ?> Add this to your single page template, after the_post(). I’d reccommend having a default header image so that if the page … Read more

Limit image resolution on upload

The problem isn’t so much the uploading itself, as that is a network connection between the client and the server. It’s not what’s eating the server’s memory. When WordPress starts ‘cruncing’ the images, that is where PHP comes in and start resizing and cropping the uploaded images. It is before this moment you need to … Read more

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