Add a default fallback for get_post_thumbnail / featured image

Since WordPress doesn’t have any support for a ”default thumbnail” and there isn’t any filters that works directly on get_post_thumbnail(),  the_post_thumbnail(), get_post_thumbnail_id(), get_the_post_thumbnail(), etc – we need to hook the filter get_post_metadata.

/*
* Fall back to a hard coded default thumbnail if a thumbnail doesn't already exist
*/
function custom_filter_get_post_metadata($metadata, $object_id, $meta_key, $single)
{

if(isset($meta_key) && '_thumbnail_id' === $meta_key)
{
//Temporarily remove filter to fetch the real data, since it's not sent as a parameter to this filter
remove_filter('get_post_metadata', 'custom_filter_get_post_metadata', true, 4);

// Get real thumbnail id
$existing_thumbnail = get_post_meta($object_id,'_thumbnail_id',true);

// Set it to a fallback ID if it doesn't already exist
if (empty($existing_thumbnail)) $result = 3372; << CHANGE THIS ID TO A ATTACHMENT ID!!!

// Re-enable the filter
add_filter('get_post_metadata', 'custom_filter_get_post_metadata', true, 4);

if(!empty($result))
return $result;
}

return $metadata;
}
add_filter('get_post_metadata', 'custom_filter_get_post_metadata', true, 4);

Almost snow

Yesterdays cold disappeared as the rain came in a sticky form of something that with a big generosity could be called snow. The lousy weather was an great excuse to sleep in… The day has been filled with som adminstrative duties, WordPress (me and Ann is co-hacking a multi-language-multi-site setup for Bonnier Business Publishing) and SEO (working on a long tail strategy with Flygstolen). And yeah, during lunch I finally took myself the time to write a post on Iphone 24.

Chilly day and storage problems

The morning started a bit earlier than usually but it took exceptional long time to arrive to the office today. Just as I was about to leave home the monitoring alerts started beeping in the phone. Several customer sites suddenly went offline as one of Swedens biggest web hosts, Binero, experienced problems with its SAN causing almost four hours of downtime. When everything finally was up and running I reported to owners of the websites and arrived to KB5 a few minutes after 2 pm.

Domain sale until end of July! $6.89 for registrations, transfers & renewals.

Until July 31:th – all customers that got totally $35 in order history at Kracked can enjoy slashed prices on new registrations, transfers and renewals on .com, .net, .info, .org, .biz, .name domains. This promo is also available for new customers who deposit atleast $35 into their account.

Since Verisign’s announced price raise (7%) on October 15:th undoubtly will lead to higher costs for all domain owners this is the perfect oppurtunity to renew your domain portfolio for several years in advance.

Until the end of the month we are also offering hosting dirt cheap: our start plan with 1GB storage is only $1.39 per month!

Login with your customer account (or create a new one) at the store to enjoy these fantastic prices!

checking whether we are using the GNU C++ compiler… no

This one was cracking my nuts for a moment:

when trying to install the freshest version of librtorrent on a vanilla unbutu box  I suddenly got this crazy error:

checking whether we are using the GNU C++ compiler… no

followed by:

 checking for proper overloaded template function disambiguation… no

configure: error: your compiler does not properly handle overloaded template function disambiguation

Kinda crazy huh? Installing the package ‘g++’ solved the problem.

Finally a good perl IDE for OS X!

For years I’ve been using the fantastic editor SubEthaEdit for all my development work in OS X. I use it for pretty much everything: editing html, text files,  code perl and php stuff, but I’ve always missed good perl integration. It has been anoying to switch to a terminal window just to debug perl code when php editing is so swift.

A few days ago I stumbled over Affrus and it was love at first sight.

Affrus offer stepped execution with breakpoints and a whole bunch of advanced features  that I miss from the well built Borland ide’s back in the DOS-days. The registration cost is almost $100 – but I’m happy to pay that when the evaluation period is over!