Set First Post Attachment as Featured Image

0 Code Snippets No Comments

Place this code in functions.php:

// featured images
set_post_thumbnail_size(450, 300, true); // width, height, hard crop

Place this code within the loop in single.php, or wherever you’d like for this to happen:

< ?php // @ post-attachment-as-featured-image/ if (has_post_thumbnail()) { // display the featured image the_post_thumbnail(); } else { // set the featured image $attachments = get_posts(array( 'post_type' => 'attachment',
'posts_per_page' => 0,
'post_parent' => $post->ID,
if ($attachments) {
foreach ($attachments as $attachment) {
set_post_thumbnail($post->ID, $attachment->ID);
// display the featured image
} ?>
fist and screwdriver

Here’s how to quickly and esily set the first image/attachment in a WordPress post as the featured image.

How to Sell Customized Products Using WordPress

0 Business owners No Comments

Here’s a pretty good writeup that I wanted to archive somewhere about how to sell customized products using WordPress. And WooCommerce, of course. Woocommerce makes selling things very easy, and I recommend it for people that are new to the online world of sales. If you have digital goods to sell, then you should look to Pippin Williamson at Easy Digital Downloads.

How to sell customized products using WordPress link

Endeavor liftoff

Here’s how to easily sell customized products using WordPress and Woocommerce.

Sublime Text Documentation

0 Development No Comments

If you use Sublime Text, whether it be 2 or 3 (or soon to be released 4!) you may have had to piece how things worked little by little and with sparse tutorials. What I’m getting at is that the official documentation is a bit thin. I personally think Sublime Text is insane, and wish every piece of software ran as quickly and effortlessly. However, not to be biased, I also like Brackets for many reasons. But I’m loyal to ST3. (I’m sure you care.)

Leave it to the open-source community to answer. This is the UNofficial Sublime Text documentation, which has been curated and maintained by Guillermo López-Anglada & The Sublime Text Community.

They’re currently running a crowdfunding campaign to produce a kicked-up version of the guide. Last time I checked, they were quite a ways from their $4000 goal. That could be due to a poor pricing structure/rewards strategy; I’ve seen that sabotage a campaign or two in my day. A crappy presentation also will kill a deal. Some of the pitches are pro-level, which will make you be resourceful if you don’t have the budget. If you feel so inclined, even as a thank-you for the existing documentation, which is really good. I’m afraid the authors may have given away too much already a,d it’s created a “why buy the cow when you can get the milk free” situation. That means they’ll need to wait for a few more serious iterations.

road to nowhere

Check out the (un)official documentation to the world’s best code editor.

How to Create a Child Theme for WordPress

0 Themes No Comments

Making a child theme for WordPress is probably easier than most people think, and good theme devs will even give you a head start and provide a child theme file template to even begin with. That gets you up and running fast, and if you use the underscores theme framework or whatever you want to call it, you’ve got a huge head-start.

The answer of how to eat an elephant holds true with learning to build child themes, though: One bite at a time. There are a numerous tutorials available that carry you all the way through in one take, but I would recommend breaking it down and really understanding what, and why, you’re doing what you’re doing. That’s why I’m posting a link to this Playlist/Series of How to Create a Child Theme for WordPress–it’s assembled into manageable pieces that are useful as references and I think, a better solution than trying to swallow the entire thing whole. The Themeshaper website has an awesome step-by step write-up on creating them as well, if you’d rather read than watch.

fist and screwdriver

If you’ve ever wanted to customize another theme, this is the correct and recommended way to do it. How to build a child theme.

How to Create Cron Jobs in WordPress

0 Development No Comments

I had heard folks talking about how to create cron jobs in WordPress as if it were a highly-advanced technique, that required the use of teams of developers and hundreds of manhours to pull off. I came to learn that a cron job is nothing more than setting a function to run at a certain time, or at a specific interval. It’s also easy in WordPress, because we have wp_schedule_event() as a built-in WordPress function. Goes to show not to listen to “people.”

wp_schedule_event looks like this:

<?php wp_schedule_event($timestamp, $recurrence, $hook, $args); ?>

Let’s say you want to set a function to run at an hourly event. All you need to do is customize the following and add it in your functions.php file:

add_action('my_hourly_event', 'do_this_hourly');
function my_activation() {
	if ( !wp_next_scheduled( 'my_hourly_event' ) ) {
		wp_schedule_event( current_time( 'timestamp' ), 'hourly', 'my_hourly_event');
add_action('wp', 'my_activation');
function do_this_hourly() {
	// do something every hour

If you want to schedule an hourly event within a plugin, you need to set the schedule for a function upon activation of the plugin. Add this to functions.php:

register_activation_hook(__FILE__, 'my_activation');
add_action('my_hourly_event', 'do_this_hourly');
function my_activation() {
	wp_schedule_event( current_time( 'timestamp' ), 'hourly', 'my_hourly_event');
function do_this_hourly() {
	// do something every hour

Then to deactivate the function, you’ll use:

register_deactivation_hook(__FILE__, 'my_deactivation');
function my_deactivation() {
WordPress speed

A cron job is setting a function to run at a certain time, or at a specific interval. Here’s how to create a cron job in WordPress:

How to Add Page and Post Specific CSS to WordPress

0 Plugins No Comments

I came across a new plugin today that allows you to add page and post specific CSS to your theme, and looks like it could be a real timesaver, in both coding and loading time. It’s called “Page Specific Stylesheets,” which is an apt name for what it does, and I can think of a few instances when this plugin ability would have been super-useful, instead of what I ended up doing. It’s only been downloaded a few times, so I mean it’s brand-spanking new.

According to the author, the plugin:

Adds a box allowing for the addition of page-specific and post-specific CSS stylesheets. Reduces the need to edit and clutter up the style.css file.

It keeps your style.css file cleaner, and alleviates the chore of a lot of extra coding in your stylesheet(s). Sounds great to me. The plugin is available in the WordPress plugin repository HERE. Try it out!

Page Specific Stylesheets plugin

This WordPress plugin attaches the styles to the page of post, allowing them to be updated just like the content is and deleted with the page.

Display a Welcome Message to Users after Login

0 Code Snippets No Comments

Add personal message to logged in users and a generic message to logged-out users. Paste this at the bottom of functions.php

add_action( 'wp_head', 'personal_message_when_logged_in' );
 * @author    Michael Musgrove
 * @example
 * @copyright 2014
function personal_message_when_logged_in() {
if ( is_user_logged_in() ) :

    $current_user = wp_get_current_user();
	echo '
'; echo 'Howdy' . $current_user->user_firstname . '!'; echo '
'; else : echo 'Hello, earthling!'; endif; }

This WP code snippet allows you to display a welcome message to logged in users, and a generic message to logged out users.

Some Obscure But Useful WordPress Functions

0 Code Snippets | Resources No Comments

If you’re a dork like me, you may spend your time perusing the WordPress Codex Function Reference, looking for valuable tidbits that might come in handy at some point in your life. There are quite a few, but here are two that should make your life easier:

Body Class Function
This functions adds nearly any class you need when building themes, and it also allows you to add whatever you want as your own. You can also filter it. How’s that for handy? Just add it to your body tag and Shazam.

<body <?php body_class(); ?> >

Many people either don’t use this, or replace it with a 3rd-party library. This function will convert an email into HTML entities to battle spam bots. Just pass it an email (and an optional mailto parameter) and tell spam to kiss it!

antispambot( $emailaddy, $mailto );

You can check out the documentation for these functions here at the Codex:

wp functions by category - the WordPress Codex

Here are two helpful WordPress functions that will save you both time and headaches: body_class and antispambot.

How to Speed Up Your WordPress Site Quickly & Easily

0 Plugins No Comments

Here’s an article I wrote for the fine people at WPBacon that dropped today, to use some lingo from The Biz. It’s a comprehensive WordPress P3 plugin review that should cover all the bases(if it doesn’t please let me know and I’ll make edits where necessary.)

Website speed is a factor that effects SEO, which you may have already known. It also impacts user experience, which should be a top priority when building and maintaining a website. So, something that helps people find your site, enjoy it more and stay there longer once they’ve found it sounds like a winner to me. Check it out!

WordPress speed

Here’s a simple and quick way to help speed up your WordPress site that adds no load time. Sound good? It is.

My 4 Must Have WordPress Books

0 Resources No Comments

Actual physical books may be under attack by tablets and people that hate knowledge, but I still maintain a library that some may think could be described as hoarding. But I rationalize it because the books I keep are either high-quality hardcover books and usually classics of their genre or what I consider essential to manage a business and my many other endeavors, such as WordPress. And if that fails I just explain I was an English major.

Developers and designers know that we’re in this for the long-haul, and “lifetime learning” is probably what draws so many of us to it, and why so many nerds are in the business. Generally, We’re good students that enjoy learning and exercising our brains. And we read.

Most of my resources are fine online, or in a .pdf or whatever. But there are 4 books that I consider essential to have on your shelf if you even dabble in WordPress. The titles and authors won’t surprise anyone, but for anyone just getting into WordPress, these books are a fantastic place to start. I searched for coupons/promo codes and bought off Amazon for Brad’s books, and even if I had to pay full retail price I would consider it a fine investment. It’s worth noting that Chris’ book is about to get an overhaul that trims it down a bit. With each release and update that needed to be included on top of the first edition, and all the new links and material that was jammed in there with each new release, the book was becoming a doorstop. So if you want the full tome you may want to act quickly.

Something that I think is great about Jeff and Chris’ books is that they’re spiral bound, so they lay flat. Nice detail which I’m sure adds to the cost, but it’s very appreciated. Note the Amazon links are affiliate, but it doesn’t affect the cost at all, and I’d recommend these regardless. While Jeff’s book on .htaccess isn’t completely specific to WordPress, the .htaccess file is so powerful and well-suited for WordPress that it’s very worth your while to learn about using it. I know it was mine.

Incidentally, these all come with downloads and an impressive amount of online resources that are super-helpful and valuable as well.

Are there any must-have WordPress books on your shelf?

professional wordpress design and development

Actual physical books may be under attack by tablets and people that hate knowledge, but I still maintain a library that some may think could be described as hoarding. But I rationalize it because the books I keep are either high-quality hardcover books and usually classics of their genre or what I consider essential to […]