Can’t find your way home?

Home is where your website starts but by default, Home doesn’t show up in your WordPress menu. Add this bit of code to your functions.php and it will magically appear:

function home_page_menu_args( $args )
{
  $args['show_home'] = true;
  return $args;
}
add_filter( 'wp_page_menu_args', 'home_page_menu_args' );

WordPress Syndication and the_content filter

We use the FeedWordPress plugin to import Twitter updates into our blog, select the most interesting ones and put them on the homepage. However, the Tweet plugin wasn’t working. After a bit of testing we concluded that the_content filters were being run but totally ignored! As it turns out (after a lot of code digging) The FeedWordPress plugin actually rewrites the content of it’s imported posts to their original values thus bypassing any the_content filters. Add the following lines of code to your functions.php to prevent this:

remove_filter('the_content', 'feedwordpress_preserve_syndicated_content', -10000);
remove_filter('the_content', 'feedwordpress_restore_syndicated_content', 10000);

Format any date according to WordPress date formatting settings

Format any date you like according to the date formatting settings in the WordPress backend with this simple piece of code. Put the following function in your theme’s functions.php file and enjoy the magic anywhere in your theme.

// $date is in yyyy-mm-dd format
function any_date($date = '2011-10-28')
{
  $format = get_option('date_format');
  return apply_filters('get_the_time', mysql2date($format, $date), $format);
}

Hierarchical WordPress templates

Another useful piece of code for you to put into your functions.php file. You probably already know that a file in your theme dir called category-1.php will be used for showing content for the category that has an id of 1. The filters below allow you to have hierarchical templates based on category id. For instance, all single posts belonging to category 1 will use single-cat-1.php. Also, all child categories of category 1 will use category-1.php.

Lees verder >

yslow

Getting good grades with YSlow – Part 1: Combining javascript and CSS files

Having a website that loads as fast as possible isn’t just good news for your visitors, it can also improve your page ranking on search engines. YSlow is a tool from Yahoo that let’s you measure just how fast your website is loading and what might be causing delays. Once installed and activated you can begin measuring your page loading speed. How well is your website performing? Ours was a C (scoring 72) before the optimizations suggested below, it’s an A (scoring 92) now. Read on for some WordPress specific tips on how you can optimize your website.

Lees verder >

Multiple permalinks for a single post with multiple categories in WordPress

Ever had more than one category assigned to a post? Did you get stuck with a single permalink where you might have wanted a dynamic permalink based on the current category? Read on and find out how to ‘hack’ your WordPress theme to make this happen.

Lees verder >

WordPress thumbnail quality

While searching for a way to change the default jpeg quality of generated thumbnails in WordPress, I came along this simple piece of code:

function jpeg_quality_filter($quality) { return 100; }
add_filter('jpeg_quality', 'jpeg_quality_filter');

Add to the functions.php file in your theme directory and change ’100′ to the desired jpeg compression value (higher is better).