Advent Calendar – Predefined callback functions for filters

Filters are often used for removing content. For example, if you want to hide the admin bar you can do the following:

function hide_admin_bar() {
    return FALSE;
add_filter( 'show_admin_bar' , 'hide_admin_bar' );

It's a bit tedious to define an additional function just to return "FALSE". Since version 3.0 WordPress provides various functions to shorten the code:

  • __return_true()
  • __return_false()
  • __return_zero()
  • __return_empty_array()

The above code can now be written as

add_filter( 'show_admin_bar', '__return_false' );

Extend the TwentyEleven Navigation with your Social Icons

TwentyEleven Screenshot

In this little tutorial we show how to add in the navigation of the TwentyEleven Theme our RSS Feed, a link with icons to our Twitter page and to our Facebook profile. Without writing a single line of PHP code. You are able to accomplish this with the WordPress Menu.

First we go in the backend to Design-> Menu and activate the CSS Classes. Therefore we click on "Screen Options" on the very top right corner. And unter "Show advanced menu properties" you check the box for "CSS Classes" and close the Screen Options.

WordPress menu screen options

After that we use the "Custom Links" to create the menu entries. We add the addresses to our RSS Feed, Facebook and Twitter and add them to the menu. There we assign the 3 menu entries to the CSS Classes. RSS Feed has the class rss, Twitter the class twitter and Facebook facebook. Don't forget to save.

WordPress Menu

I prepared a sprite, which you can download with a right mouse click->Save Image As… . You have to save this sprite into the folder twentyeleven/images/.

Social Sprite

Then we open the file TwentyEleven style.css with a text editor and add at the end of the Menu block #access our additional CSS. We do not have much to add. We let our 3 list items float to the right, push the text out of view and position the graphic. Only for the hover, focus and active states, we must define a little tricky CSS rule in order to circumvent the background gradients of TwentyEleven.

#access .twitter, #access .rss, #access .facebook {
	float: right;
#access .twitter a, #access .rss a, #access .facebook a {
	background: transparent url(images/social-sprite.png) 0 0 no-repeat;
	padding: 0;
	text-indent: -9999px;
	width: 70px;
#access .rss a { background-position: 0 0; }
#access .facebook a { background-position: 0 -96px; }
#access .twitter a { background-position: 0 -48px; }
#access .rss a:hover, #access .rss a:focus, #access .rss a:active {
	background: transparent url(images/social-sprite.png) 0 -144px no-repeat;
#access .twitter a:hover, #access .twitter a:focus, #access .twitter a:active {
	background: transparent url(images/social-sprite.png) 0 -192px no-repeat;
#access .facebook a:hover, #access .facebook a:focus, #access .facebook a:active {
	background: transparent url(images/social-sprite.png) 0 -240px no-repeat;

This is just an example to experiment. Add your Google+ profile and expand this example with cool CSS tricks!

Advent Calendar- How to disable comments for WordPress pages in any theme

Usually you don’t need comments on pages. Unfortunately, WordPress doesn’t offer a separate option to leave comments on posts on and turn them off for pages. If your theme calls comments_template(); in its page.php and you don’t want to break automatic updates, you cannot just remove the function call, because it will be overwritten with the next update.

No problem. There’s an hook for that. It’s a filter called … wait for it … comments_template. We can change the path to the comments template here – if haven’t figured that out already. Let’s build a small plugin.

So, what do we do? We hook into comments_template(); and change the path. Our new path should point to an existing file without any HTML output. In this case, we use just our plugin file, because we know it exists and we control the output.

As you may have noticed our plugin file is included two times: First as a plugin, later as a replacement for comments.php. The function_exists() check prevents any You cannot redeclare … errors.

Putting this all together …

<?php # -*- coding: utf-8 -*-
Plugin Name: Disable Comments On Pages
Version:     1.0
Author:      Thomas Scholz
Author URI:
License:     GPL
// This file is not called from WordPress. We don't like that.
! defined( 'ABSPATH' ) and exit;

// If the function exists this file is called as comments template.
// We don't do anything then.
if ( ! function_exists( 't5_disable_comments_on_pages' ) ) {
	 * Replaces the path of the original comments template with this
	 * file's path on pages.
	 * @param  string $file Original comments template file path.
	 * @return string
	function t5_disable_comments_on_pages( $file ) {
		return is_page() ? __FILE__ : $file;

	add_filter( 'comments_template', 't5_disable_comments_on_pages', 11 );

Advent Calendar – Only Update The Core – The Fast Way!

Advent Calendar #1Same procedure as every year! Most of our readers already know of our Advent Calendar tradition, which we have every year before Christmas. What exactly an Advent Calendar is all about, that is explained on this post.

We open a door every day, which contains a little gift for our readers, by providing them a WordPress tip or trick each day until December 24th at WP Engineer. So we hope you will be exciting to see what tip, hack or news will be behind the door the next morning. Enjoy a new little WordPress gift every day until December 24th.

Here goes our first door

Since WordPress version 3.2 updating an existing installation is faster. A constant entered in the wp-config.php makes sure that everything in the folder wp-content won't be touched and so are Plugins or Themes, which previously came along in the Core won't be updated or reinstalled.

// Make WordPress core updates only update the core

And tomorrow another door will be open of our Advent Calendar!
Also the hint: if you would like to write a guest post, please send us your topic or content via eMail.

WordPress Jeopardy

The idea of a little game in WordPress came at the WordCamp Switzerland in early 2011. For an interactive session at the WordCamp Germany in Cologne in 2011, one of the creators Thomas, thought that it’d be nice to have a game-session.

On 24th of September started the first WordPress Jeopardy Game Session. For that, the whole room was divided in two teams to battle each other. The points were counted, but nobody really knows who won.
Continue reading …