Archive for the ‘Tweaks and tricks’ Category

How to work with WordPress featured images

WordPress has come a very long way (especially since v3) in terms of its image or media management system, making it extremely easy for you to add custom image sizes, featured images, cropping etc.

Theme developers are now spoilt for choice when it comes to adding image management capabilities to their themes, and users have more control than ever before on how they add and manipulate the images they upload.

These improvements however, bring a level of complexity that can only be understood through hours of research and practice to get the perfect balance in terms of how images are added and manipulated from an extension or theming perspective.

Fortunately, Ade, over at www.studiograsshopper.ch has come to the rescue and done all the hard graft for you already.

Ade has meticulously studied and documented every aspect of how wordpress’s media system works and how best you can approach its implementation.

We were amazed at the level of detail Ade went into in order to make this topic extremely clear for everyone and are sure you will be as well: “WordPress Featured Images – add_image_size() resizing and cropping demo

How to open the comments author link in a new window

Posted on: 1 Comment

On most wordpress stock themes, you will find that when the user clicks on the comment author link. It opens directly in the same page, taking the user away from the site.

Ideally when the user clicks, it should open the commenters site in a new window. After all, they are being directed to a new website.

Amazingly it seems most suggestions you will find on Google for this is to modify the wp includes core files. This is never ideal and the better approach is to use WordPress’s filters instead. After all, this is exactly what they are for!

What we are going to do is add a new function that includes the link structure how we want it, using the original structure as a base, then run a filter on the “get_comment_author_link” to change it with our new function.

So open up your themes functions.php file and somewhere at the bottom, add the following. I have added comments on each section of the function so you can easily understand whats happening.


function comment_author_add_blank() {
	global $comment;
	//get url
	$url    = get_comment_author_url();
	//get author
	$author = get_comment_author();
	// check if user added a url or not
    // if no url, return author
	if ( empty( $url ) || 'http://' == $url )
		$return = $author;
	// if has url, return url with new format and _blank
	else
		$return = "<a href='$url' rel='external nofollow' target='_blank'>$author</a>";
	return $return;
}
// now run the filter on our new function
add_filter('get_comment_author_link', 'comment_author_add_blank');

Thats all folks!