Easy Post Thumbnails

Preview

[snap url="http://blogs.henrico.k12.va.us/21" alt="Preview" w="400" h="300"]

The thumbnail above was generated through the WordPress Snap plugin using the code above. It’s a quick easy way to add visual elements to your site. It seems to take a while to create for sites not already in their database but it opens up some really nice options.

I’ve often wanted to automatically put thumbnails into posts linking to URLs but all the previous ways I found to do it relied on companies I didn’t like or had other shortfalls that ruled them out. There are a number of projects where we’d like to have this happen. We’ve been using Press This but in some cases I wanted to make the image addition automatic to simplify things for the author.

I sat here for a few minutes and figured I could probably make this happen if I knew how to code stuff. I don’t know how to code but I figured I’d try anyway.

Below is my first stab was at messing with the bookmarklet that allows the Press This to work. First stop, WordPress Codex – documentation there was somewhat sparse. I couldn’t find the word “via” which shows up when you use Press This so I now knew there had to be something else involved in how this works.

I wandered around a bit and eventually found the press-this.php file in wp-admin.

This is what I wanted.

I did a quick search in the file for “via” (when you “press” something it’ll say “blah blah blah” via Blah) as that was likely to be in the general area of what I wanted and it was in English so I’d be able to find it. Sure enough, I found the following chunk of code.


if ( $url)
if ( $selection )
echo wp_richedit_pre($selection);
if ( $url ) {
echo '

';
if ( $selection )
_e('from ');
printf( "%s.

", esc_url( $url ), esc_html( $title ) );
}

I know only enough to puzzle the idea of the lines out. You can see in the printf line that it’s grabbing the URL and formatting it. That’s essentially what I wanted to do but with slightly different wrappers. I wanted the same variable- the URL. So I messed around with things for a while and eventually wrote the one tiny line below.

printf( "My Thumbnails", esc_url( $url ) );

I leave it in context below for those as clueless as I am.

It works. That’s always nice. In the near future I’ll add the image size parameters and maybe try a few other things.

Anyone who wants to let me know how to improve things or warn me that I’ve done something terrible, your comments are more than welcome.


if ( $url)
printf( "My Thumbnails", esc_url( $url ) );
if ( $selection )
echo wp_richedit_pre($selection);
if ( $url ) {
echo '

';
if ( $selection )
_e('from ');
printf( "%s.

", esc_url( $url ), esc_html( $title ) );
}

Comments on this post

No comments.

Leave a Reply

Trackbacks and Pingbacks on this post

No trackbacks.

TrackBack URL