WordPress dev tip: How to move the Featured Image box up… to just below the Publish box

Whenever I’m doing development on a WordPress site that makes heavy use of taxonomies (it happens with meta data-rich portfolios for architects, for instance, which seems to be a niche for me), I get really annoyed with how much WordPress devalues the Featured Image meta box. I don’t want it shoved way down below all of the taxonomies, mainly because users will probably forget or never even know that it’s there!

What I really want is to have the Featured Image box near — but not at — the top of the sidebar. Specifically, I want it to come just below the Publish meta box.

I’ve found some resources online that almost got me there, but not quite. However a minor tweak to this example solves the problem for me.

I’m taking some shortcuts here, some of which you may not like. First, most tutorials on manipulating meta boxes encourage you to remove them and then add duplicates with a slightly different ID. I think what’s happening here though (not having inspected the source code!) is that your modifications to the add_meta_boxes action run before the standard WordPress meta boxes get loaded (possibly/probably because, as you’ll see, we’re setting the priority to high), so if you’ve created one with the same ID as a default box, yours takes precedence.

The other shortcut I’m taking, which I suspect will be more controversial (but it’s just the way I like to do this) is that I am creating an anonymous function directly within the add_action() call. That’s just a personal preference, but I like to do it because 1) it keeps the code more compact and 2) it avoids creating a bunch of named functions that have no business ever being called anywhere else anyway.

So what’s happening here? First, I’m creating the Publish meta box. Then I’m creating the Featured Image meta box. By giving them both high priority, WordPress makes them the first two meta boxes in the sidebar. The reason I have to create the Publish meta box is that, if I didn’t, Featured Image would come first, above it. I don’t want that.

I’ve set the $screen parameter to null so this will happen on all editing screens, but if you only wanted to move Featured Image up on posts and not on pages, for example, you could set it to 'post'.

Here’s the full code:

add_action('add_meta_boxes', function() {
  add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', null, 'side', 'high');
  add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', null, 'side', 'high');
});

For more background, check out the official documentation on the add_meta_box() function.

What’s that close paren doing after my video embed in WordPress?

Working on a new client site that has a lot of YouTube video embeds, I was alarmed this morning to find a stray close paren ) character in all of the posts right after the videos.

Knowing I had recently been tampering with the embed_handler_html and embed_oembed_html filters in the site theme, I figured it was something I had created. So I set about debugging my code but couldn’t get anywhere.

I decided to see if it was in fact a new problem in WordPress itself, by setting up a test post on this site with a YouTube video embed (this, of course). Sure enough, even on my unadulterated theme, the stray close paren appears.

Look at it!!!I mean, just look at it!!!

Anyway, I hope/assume this will get fixed in the WordPress core soon, but in the meantime if you are running into this problem and want a quick fix, and you’re not afraid of editing the functions.php file in your theme, have a go at this little addition that will strip out the offending punctuation:

function embed_fix_stray_parens($content) {
    return str_replace('</iframe>)','</iframe>',$content);
}
add_filter('the_content','embed_fix_stray_parens');

Update #1: I went to submit a bug report to the WordPress development team and found my report was a duplicate of this one. If I understand correctly, the close paren is actually being delivered by YouTube itself, not WordPress, via the oEmbed request. Isn’t the Internet fun?

Update #2: This really is YouTube’s problem… it even shows up in the embed code you get on their own site:

Screen Shot 2014-03-12 at 11.00.12 AM

This issue is also showing up on StackOverflow now, including a more efficient temporary workaround for WordPress sites than my own hasty solution.

Room 34 on iPhone

iPhoneI finally got myself an iPhone on Thursday. In fact tomorrow I will have two, which is one more than I need (and is also a story for another post), but the point right now is that I finally have an iPhone.

Naturally one of the first things I did with the iPhone was take a look at how room34.com looks on the iPhone. And since the iPhone’s Safari browser works pretty well, it looked fine. But since it’s optimized for a 1024×768 display, it also was a tad small.

By now I am all set to create an iPhone-friendly version of the site, but since it’s built on WordPress, I was pretty sure someone would already have created an iPhone-friendly theme, and sure enough, someone did. But they actually went one step further and built it as a plug-in, so you can keep your regular theme for computer-based visitors and mobile users will automatically see the mobile version. Nice!

It’s a bit plain for my tastes, and it doesn’t account for the fact that I’ve built my own navigation bar and menu system for browsing the non-blog pages of my site, but it’s a start. I plan to customize it over the next week or so to look more Room 34-ish, and to include all of the necessary navigation.

Progress…

I realized what a daunting task it was going to be to use the built-in WordPress functionality to manually copy over all of the articles from my old site database, so I dug under the hood and used the power of SQL to just more-or-less dump everything from one database into the other. So now all (well, most) of the stuff is moved over, and I can begin to disassemble the old site (currently lingering in the link set as “Room 34 Cold Storage”).

If you care to look back at the old stuff (and why wouldn’t you?), you may notice some oddities… that’s mainly due to inconsistencies between my idiosyncratic HTML and the fancy formatting/clean-up WordPress does. I’ll gradually fix that stuff… maybe. (Right after I get around to organizing the basement.)

I’m also tinkering more with the themes. I’ve downloaded several interesting themes that I plan to try out for a while, to get a feel for both their visual appeal as well as the ways they handle certain technical features of WordPress. Once I find one I like, I’ll use it as a basis to build my own, one that incorporates my photography as well. (Will the excitement never end?!)

Oh, I almost forgot to mention… some of the old stuff didn’t have dates, so I hastily and more-than-somewhat arbitrarily assigned them all to January 1, 2004.