Excerpts and not full content, but only sometimes

WordPress filters and actions remains one of my favorite features. There is so much that you can easily manipulate without modifying a theme’s files.

For example: on my front page I like the latest published post to show the whole content with a featured image if there is one. For the rest of the articles I want to display the excerpt and no featured image. This is the same on the front page and subsequent pages.

One way to do this is to create a child theme and modify the PHP to get the effect you like. There’s a few reasons why I don’t like that option.

  1. Child themes are fun and I always recommend users create them. But I’m bad at maintaining them when the parent theme is updated.
  2. My CSS is just awful and I’m pretty sure I’d break the responsiveness of my site.
  3. Filters are cool! I can use this code in a plugin.

Filter the_content

I took a shot at making my own filter but a quick search found that Justin Tadlock had written a really good post on the topic already in 2008. I use that code in my function but added a few lines.

// Get the ID of the last published post
$mh_last_id = wp_get_recent_posts( array( 'numberposts' => '1' ,
     'post_status' => 'publish' ) )['0']['ID'];

// Get the post format. If the post is a standard format then the value will be false
$mh_post_type = get_post_format();

I do not want to show an excerpt for the latest post  and only want to modify standard post formats. Anything else I want to skip. The reason I only want to play with standard format posts is that other post types break horribly when I force the excerpt this way.

Except for adding to the conditional statement, the whole function is copied from Justin’s post. He writes great code and explains it much better than I do.

// If is the home page, an archive, or search results and not the last post and is a standard format
if((is_front_page() || is_archive() || is_search()) and $mh_last_id != get_the_ID() and !$mh_post_type )

That’s a little ugly to look at but it does the job.

What about the featured image?

In the past when I wanted to hide the featured image in a child theme I would use CSS like so.

.ryu-featured-thumbnail, .attachment-ryu-featured-thumbnail, .wp-post-image {
     display: none;

Which works but is a little heavy handed. My WordPress installation still sends the HTML for the featured image and the browser still pulls that image. The end user just doesn’t see it because it’s not being displayed.

I don’t want to remove featured image support from the theme and I don’t want to send that HTML either. Thanks to the post_thumbnail_html filter I don’t have to.

add_filter( 'post_thumbnail_html', 'mh_post_image_html', 10, 3 );

function mh_post_image_html( $html, $post_id, $post_image_id ) {

// Get the ID of the last published post
$mh_last_id = wp_get_recent_posts( array( 'numberposts' => '1' ,
     'post_status' => 'publish' ) )['0']['ID'];

if ( (is_front_page() || is_archive() || is_search()) and $mh_last_id != get_the_ID() ) {
     $html = '<!-- Featured image not displayed in excerpt -->';
return $html;

This code checks if we’re the first post and replaces the post_thumbnail_html with a simple HTML comment.

Child theme or plugin?

This code works either way. At the moment I am using this in a plugin but the whole thing can be implemented in my child theme’s function.php file.

It belongs in the child theme because I’m playing with the presentation and that is theme territory. Editing a copy of content.php in the child theme directory would be more theme’ish but I like filters. Filters are cool.

I’m not good at keeping my child theme changes in sync with the parent theme so using a filter lets me just play with the results and not mess with theme files. In a plugin or the child theme’s functions.php file the filters still work the same.

Favorite new WordPress 3.9 feature

Copying and pasting from Microsoft Word directly into the Visual Editor is my new favorite thing in 3.9 beta. I just tried it on Lily’s store WordPress site and it worked alright. This is a fortunate side effect of 3.9 getting a new version of TinyMCE.

I know, that sounds anti-climatic even a little mundane given the great enhancements that 3.9 will be delivering. But I occasionally (once a month) have this conversation.

Them: How can I copy this Word document into WordPress?

Me: First select the text and paste that into notepad. I like notepad++ myself.

Me: Then you take the text you just copied into notepad select and copy it into the Visual Editor. Again.

Me: Make sure you copy from notepad. Bad things will happen if you paste that into the Visual Editor directly from Word.

Me: Then you apply the styling such as bold, underline, etc. To that text. For titles I like to use the <h3> tag myself.

Me: No, that layout thing you did in Word won’t work.

Me: Images? If you use the Snipping Tool then you can save that image to your hard disk.

Me: Once you’ve done that, upload that into the media library.

Me: Then you can insert it into the WordPress post. The image I mean, I usually go with centered and no link.

Them: Zzzzzz Wha-? What we’re we talking about??

I myself don’t like the idea of users creating content for WordPress outside of WordPress but I’m told I’m special. Apparently “regular” users (yes I’m doing the “air quotes”) such as my wife and some siblings use Word that way.

Lily creates flyers for wine tastings once a week. Right now she has to wait for me to create the event on the WordPress site (thank you Modern Tribe! that’s a great plugin) then cross post it to the company Facebook page. If I can show her how to just paste the content into WordPress to create the event then she can deliver the post sooner.

Also that means I’ll have one less thing to do each week.

Next I have got to test out dragging images into the Visual Editor to upload them that way. That’s got to improve “regular” users workflow too.


Some journalists still inspire you


Miles O’Brien has always been one of my favorite science reporters and I was sorry to hear about the loss of his left arm.

You know he’s going to get through it but it’s horrific that this could happen to him. Give a few minutes and see his interview on PBS NewsHour. It’s great to see him moving forward and explain his phantom pain and what he’s going through.

His Contaminated Waters report is informative and I look forward to seeing what he produces next.

WordPress actions and filters are still very cool

I spend time perusing the WordPress support forums (now that’s an understatement) and sometimes I come across someone being unhappy with a plugin. In this particular case a plugin was adding a notice to the admin screens saying “Upgrade now for only $24″.

I really have nothing against plugin authors deriving income that way but I prefer that messages like that in my WordPress dashboard be dismissible. That dashboard real estate is mine and I just don’t like to share.

The plugin adds that message using this code.

add_action( 'admin_notices', 'emg_upgradepro_message' );

WordPress actions and filters are a wonderful thing. It’s a queuing mechanism meaning that the order that your PHP code loads or is executed does not matter. What matters is that actions (or filters) get added to the queue and executed in priority order.

That add_action() does not have a priority so it defaults to 10. Actions that are added that way can be removed too but you have to have that remove_action() in the queue after the action is added. You can’t remove it before it’s added.

I was able to easily (took me 3 minutes) by creating another plugin that just removes that action like so.

Plugin Name: Remove Easy Media Gallery Upgrade Notice
Version: 0.1
Description: This plugin removes the Easy Media Gallery Upgrade notice in the WordPress dashboard.
Author: Jan Dembowski
Author URI: http://blog.dembowski.net/

add_action( 'admin_init', 'mh_no_upgrade' , 15 );
function mh_no_upgrade () {
        remove_action( 'admin_notices', 'emg_upgradepro_message' );

And that’s it. The priority 15 should make it run after the action that adds that message and it does: the message is gone. This may not be the best way to do it but it’s an easy 3 minute fix.

Keep in mind that I don’t use this plugin on my main blog but exercises like this one just show how easy it is to extend WordPress.

“By the end of the war it was deemed inadequate”

Today we went to a nearby shopping outlet (I got sandals) and they had a section for the Museum of American Armor. This is an off shoot of the American Airpower Museum which the kids and I visit a lot.

My 11 year old son is a WWII armor vehicle buff. He looked at a vehicle labeled the M-8 Greyhound and started explaining that the placard said wasn’t for that vehicle. That vehicle on display was the British Bren Carrier.

This impressed the museum guide and when he got to the 57mm anti-tank canon my son replied like so.

Yes, but by the end of the war it was deemed inadequate. The 57mm anti-tank canon was adequate for fighting earlier German tanks like the Panzer I, II, and III. The Panther had thick sloped armor that shells would bounce off. They got the idea from the Russian T-34/76 tank.

Seriously, he said that. I just asked him to repeat it in case I got it wrong.

He’s been reading and has a few books on the topic and for the last couple of years has become an expert.

The museum guide was wowed and suggested that he should sign up to give tours. I think that’s a great idea and it would really build a lot of confidence for him. Hopefully next spring the museum will break ground in Bethpage and we’ll visit them regularly. In the meanwhile we’ll see the armor on display at the American Airpowered Museum this Labor Day weekend.

Advice for aspiring R/C backyard bashers

There are two types of people who play with R/C cars: serious racers and backyard bashers.

Racers are the one’s who start with an RTR or build-it-yourself kit and commence to customize their car for better acceleration, traction, and overall performance. They assemble their own tires, balance the wheels (on a 1/10 scale car!) tune the suspension, select and break in the motor etc.

Racers are hardcore R/C car enthusiasts. I don’t know any racers.

Backyard bashers are everyone else. Me and the kids are into bashing meaning we race around, jump of home made ramps and we break things. Here’s some tips.

Do your research and start with RTR kits

RTR kits stand for Ready-To-Race or Ready-To-Run depending on who you asked.

My brother got a couple of Traxxas Nitro cars but I decided that I wanted electric and shopped around for a good Kyosho model. My last R/C car was a Kyosho Ultima and I thought they’d have something for me.

That was a wake up call. Kyosho is a fine R/C car manufacturer but no one in Long Island sells them. So I went to look at blogs for inspiration and made my way to Jang’s UltimateRC YouTube channel and forums.

Jang’s reviews are really good. He covers what he likes and dislikes as well as does a durability montage. It was his Bandit XL-5 review that convinced me that the kids could handle getting one. We upgraded to the VXL LiPO version and the kids are having a blast.

Thanks to those YouTube videos I got a good idea that Traxxas is just right for durability.

If you do go electric stick with 7.4v LiPO batteries

My R/C car is a Traxxas Rustler VXL and the kids have a Bandit VXL each. They each came with a Traxxas 3300mah 7.4v 2s 25c battery. I wanted another battery so I took the advice of one of the hobby store guys (they’re very cool) and got a Venom 35C 3S 5000mAh 11.1v LiPO battery. Yay! More current! More voltage! The car goes noticeably faster!

It also doesn’t last as long. Using the 3300mah batteries I get about 20 minutes of run time. With the bigger 5000mah pack I get about 15. Going forward I may get a high capacity 7.4v battery but unless I’m racing (and I never will) I’ll stick with more play time versus more speed and power.

LiPO batteries are scary

OK they’re not really scary but the do have some risks especially if you puncture them: these batteries can catch fire. That’s if you abuse them; if you treat them as they should be handled then you will be fine.

This is the reason the kids cannot charge these batteries. When they get them to plugin into their cars I make sure to supervise them. They know to treat the batteries with respect and handle them carefully.

I haven’t yet but I am getting a LiPO charging bag as well as a fireproof box for storing them. I don’t really think I need that but A) you never know and B) parents need to set good safe examples for kids. Safety is not a game.

Visit and make friends with your local R/C dealer

You are going to break R/C car parts. Yes, you can get any of those parts online but getting them locally is faster and you’re local shop will take care of you.

I live near a shop called Elwood Hobbies and they’ve got parts, tools, kits, everything. I could probably rebuild my entire car just from the parts they already have in stock. If they do not have anything they’ll get it. They also service vehicles from big 1/8 scale nitro cars to R/C helicopters. They really know what they are doing and prevented me from making a few boneheaded mistakes already.

Find your local shop and get to know them. They’ll have parts plus advice and you’ll be glad you did.

Expect to buy upgrades

A not very sensitive friend of mine visited while I was replacing stub axle carriers on my son’s Bandit. My son broke them and I replaced them with aluminum versions. He summed up his thoughts concisely.

“Wow, what a scam! And the lexan shell uses cancer causing paint too???”

He’s like that. We all still like him anyway.

What he was referring to is that when I break things I upgrade to the anodized aluminum parts if I can. I didn’t just buy R/C cars (Lily is a very tolerant woman) I also had planned to maintain these cars.

This is not an inexpensive hobby. I limit the amount I spend simply by buying from a durable manufacturer. Our R/C cars will not win any races but high speed 10 foot jumps are usually alright.

Even if you destroy them it’s all good fun

This is a hobby and you may eventually ruin your toy. I mean R/C car. It’s happened to my brother and sort of happened to me in the past.

That’s fine and this hobby is all about fast, fun, and more fun. The kids and went to a parking lot nearby and had had hundreds of feet to zip around in all directions. It was great! And we broke all three of are cars in minor ways.

Using the tools that came with our cars (another upgrade coming soon) I was able to get 2 of the cars working for a while longer. But if the kids and I had wrecked them then we’d be upset but it would be alright. These little rockets move around 30 miles per hour and you can’t change physics.

I’m having a little unique fun with my kids. Even my daughter likes her customized R/C car (although I do wonder how much of this is just about competing with her brother). They’re learning to take care of their expensive toys and I’m learning to be more patient and tolerant of our mistakes. That experience alone makes me recommend these to any Dad.