Make wp-caption the same (responsive) width as the Image

Posted on

I was working on a problem last week in WordPress where the caption for an image was extending the whole width of the container, not staying the width of the image. This make sense – the image is inside the .wp-caption container. So how to we fix it? Let me tell you!

Continue reading “Make wp-caption the same (responsive) width as the Image”

Add Attachments to WordPress Search Results

Posted on

I feel like this has to have been done a lot, and there are great plugins out there for it, but if you’re just looking to add a quick function to your theme (or a really simple plugin) yourself, here’s how to modify WordPress’ search query to include attachments (like images).

function attachment_search( $query ) {
    if ( $query->is_search ) {
       $query->set( 'post_type', array( 'post', 'attachment' ) );
       $query->set( 'post_status', array( 'publish', 'inherit' ) );
    }
 
   return $query;
}

add_filter( 'pre_get_posts', 'attachment_search' );

This does 2 things: includes posts of type ‘attachment’ to the search query, and adds the post status of ‘inherit’. This will ensure that any images (or other attachments) that were added while adding a new post or page will be included in the results.

You can also extend the post type array to include your own Custom Post Types (eg array(  'post', 'attachment', 'products' ); )

These 2 posts were very helpful in getting this code together:

Workflow, Responsible Responsive Design, And More Friday Links

Posted on

I have already come across a few things this morning that I’ve wanted to share out, so it seems a short blog post is in order!

  • Profession Workflows & Best Practices | WPSessionsBrian over at WPSessions is hosting a free seminar on best practices for development and you shouldn’t miss it! It’s going to be a great learning opportunity for anyone, whether you’re new, a freelancer, or work with these tools every day. I can’t wait for this one!
  • Pixact.ly: This is a fun little game that shows you how well you can eyeball pixel values. I’m just OK. How do you measure up?
  • Sleeping Position by Profession: Funny and pretty accurate from my experience.
  • Story.AM: This service that’s launching soon. From the site: “Create and sell interactive longform stories on a collaborative platform built for storytelling.”
  • Responsible Responsive Design: The latest book by A Book Apart, penned by Scott Jehl. This is bound to be a good one. I can’t wait to read it.
  • Silicon Valley Job Title Generator: What are you? This morning I got “KICKSTARTER EVANGELIST.” Funny because yesterday, I blogged all about Why Kickstarter is bad for Christmas Gift (what I don’t mention in the title is what I think it’s great for).

Directory Handler at Theme Forest

Posted on

I’m happy to announce my first Theme Forest component, Directory Handler. it’s a simple set of 2 classes that handle (in several ways) listing the contents of a directory. The main class, DirectoryHandler, includes several functions that:

  • Get and/or print the entire contents of a directory
  • Normalize the name of a file or directory (replace special characters with spaces)
  • Return the extension of a file
  • Return all of the files of a directory in an array
  • Return all of the sub directories of a directory in an array

TheImageDirectory class extends the functionality of DirectoryHandler by changing the get and print directory functions to:

  • Print a thumbnail version of the image
  • Integrate lightbox for easy image viewing/browsing.

You can view a live demo here and Download the full documentation here.