Add Avatar To WordPress Default

Avatars are popular as identification and with the service Gravatar it is largely used in the comment area of different applications.
WordPress allows the user some basic settings. For example loading a default or generated Avatar, if the commentator doesn't have one.
Various themes have a standard Avatar to match the design. But even here there is a nice solution via a hook, which enables to add an avatar in the list of your backend to make a selection quite simple. In the following I would like to show with a short and simple code snippet how to add 2 new avatars to the array of WordPress.


You have to add this little function to functions.php of your theme and it will add 2 Avatar from your folder images of your theme directory. I suggest, that the Avatars have a size of 60 pixel.

 * add a default-gravatar to options
if ( !function_exists('fb_addgravatar') ) {
	function fb_addgravatar( $avatar_defaults ) {
		$myavatar = get_bloginfo('template_directory') . '/images/avatar.gif';
		$avatar_defaults[$myavatar] = 'people';

		$myavatar2 = get_bloginfo('template_directory') . '/images/myavatar.png';
		$avatar_defaults[$myavatar2] = '';

		return $avatar_defaults;

	add_filter( 'avatar_defaults', 'fb_addgravatar' );

Is the theme active, you will have the 2 new Avatars available in your list.

Identify Authors With Gravatars

Since WordPress version 2.5, it is easier to include the Gravatar of a comment author in the comments. WordPress offers a feature that is easy to use and it brings some parameters with. In order to use and how to include a Gravatar, I would refer to the article „Gravatar Use Easy“.

But with this feature you can do more. Magazine-style for blogs are currently in high demand and many blogs have a a couple of authors. Many times the blogs link and present the author of the respective contribution. WP offers a whole range of template tags to this functionality, check out Codex.

Now it would be nice to give the author a face. Continue reading …

Update Informations Only for Admins

If you only want to let users, who are privileged to receive information about updates and plugins, you should copy the following code to your functions.php of your theme. These users have to have the right "edit plugin" (edit_plugins) to receive updates.

Alternative: use the plugin Secure WordPress, the plugin has inside the function to active this possibility.

 * remove core-Update-Information
 * @rights:
if ( !current_user_can( 'edit_plugins' ) ) {
	// core update
	add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ) );
	add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) );
	// plugin update
	add_action( 'admin_menu', create_function( '$a', "remove_action( 'load-plugins.php', 'wp_update_plugins' );" ) );
	add_action( 'admin_init', create_function( '$a', "remove_action( 'admin_init', 'wp_update_plugins' );" ), 2 );
	add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_update_plugins' );" ), 2 );
	add_filter( 'pre_option_update_plugins', create_function( '$a', "return null;" ) );

Google News To Release With WordPress

Google News can be a coveted platform. But Google needs for the aggregation a special format - News Sitemap.

Basically you can create this format in two ways with WordPress. Both solutions will be presented here. I will talk about the second example more in detail, because I believe it shows very nicely how to use content from WordPress outside your blog.

  1. The first way is to create a sitemap, similar to a feed in WordPress. This has several advantages for the administration in WordPress.
    How to create a feed, I have in the tutorial „WordPress Feed for Drafts“ shown. You can download this solution as a plugin and simple use Google News-Sitemap.
  2. A second possibility is to create a PHP file in the root directory and to write the latest posts into the appropriate format.

Continue reading …

Easy Way For Advertisement In WordPress

Since version 2.5 WordPress introduced the shortcode API, more detail about it in our article „WordPress Shortcode API“. Recently I had a task which is surely common, but with the help of shortcode API and custom fields very easy to solve. I had to include some advertisements (in german: Werbung) into some articles.

In each article the editor puts 3 custom fields: bild (image), link, linktext. In the text he can set the shortcode [ad]. This shortcode will be recognized by WordPress with the help of the following function. It will also load specific data to display the ads here.
Continue reading …

How To Improve WordPress Plugins

Icon for Menu

Icon for Menu

With the upcoming WordPress release version 2.7 the menu changes to the vertical. This offers several features to the author which we already mentioned in some other posts. But this time I explicitly address Plugin authors and ask them to make their Plugins more user friendly in terms of usability. I will show only two tiny features.
Each of them have been discussed several times on the wp-hacker-mailing-list, but nearly everybody considers them as big improvements to usability.
Continue reading …