Mar 14

Using the Thesis Theme and Yoast's WordPress SEO plugin

I share the view of other WordPress developers who believe that SEO functionality should not be incorporated into a WordPress theme – it should be in a plugin. This promotes modularity and maintainability and avoids vendor lock-in. If you ever want to change the visual appearance of your WordPress site, your site’s SEO will not suffer.

One of the key selling points of the Thesis Theme – one of the best known premium themes for WordPress – was its inbuilt support for SEO. At the time that the Thesis Theme was first released, its inbuilt SEO features may have been equal to or superior to separate SEO plugins, but times have changed. I am not as critical of the Thesis theme’s native SEO capabilities as some other people, but one definitely can do a better job using some of the SEO plugins out there.

One highly-rated SEO plugin is WordPress SEO by Yoast (Joost de Valk).

Unfortunately, if you attempt to activate this plugin whilst using the Thesis Theme, you will have the problem of duplicate meta tags. You see, the Thesis Theme does not have a configuration option to disable its own HTML meta tag generation. As a result, when you access a page, it will contain both Thesis’s SEO meta tags those generated by the WordPress SEO plugin, which is likely to confuse search engines.
Continue reading »

Tags: ,

Mar 03

In the past, the majority of WordPress themes would enclose the title of sidebar widgets within an HTML h3 heading tag. The Thesis Theme V1 is one such theme.

WordPress theme designers have moved away from this practice because of an increased awareness of SEO. Nowadays, people who write search engine optimised content generally use HTML heading tags exclusively for hierarchical text elements with relevant contextual keywords designed to appeal to search engines, e.g. a post title with the main target keyword would be enclosed within h1, then the subheadings with additional keywords would be enclosed within h2, and so on.

In contrast, WordPress widgets often have generic titles like ‘categories’, ‘tags’, ‘meta’ and ‘links’ which have offer no usefulness as search keywords. Having h3 on these is wasteful as it has the potential to take value away other relevant keywords on the page.

The Thesis theme does not have a hook to change the styling of widget/sidebar titles. The solution is to unregister the two default sidebars, then re-register them with a different html markup for the title. In this example, h3 has been replaced by a div with the class “widgettitle”.

Furthermore, we have to ensure that this only happens AFTER the Thesis Theme has finished its default sidebar registration. This is achieved by hooking the action ‘widgets_init’ with a priority of 11 – lower than the WordPress default priority of 10.

The following code snippet should be added to custom_functions.php in the Thesis Theme’s custom file editor:
Continue reading »

Tags: ,

Mar 03

Sample 404 Error Image

This article describes how to get the Thesis Theme Version 1 to display a 404 error image as a substitute for any missing images on your site.
Continue reading »

Tags: ,

Mar 03

Sample 404 Error Image

If you attempt to access the URL of a non-existent image file on a website – say a jpg, png or gif file – you will usually be redirected to the 404 error page. If the image is embedded via an HTML img tag, this will normally result in your browser displaying a missing image icon.

Instead, we can handle this in a more elegant way by creating a special 404 Error image which will be returned when someone attempts to request a non-existent image file on your website.

All we have to do is:
Continue reading »

Tags:

Mar 03

This snippet of PHP code takes any shortened URL, like those from Bitly, Google or Twitter, and expands it into the full and final destination URL.

function expandShortUrl($url)
{
	$headers = get_headers($url, 1);

	$loc = $headers['Location'];
	if(is_array($loc))
	{
		// get the highest numeric index
		$key = max(array_keys( $loc));
		return $loc[$key];
	}
	else
	{
		return $loc;
	}
}

Hat Tip: Deluxe Blog Tips and Karl Groves – Easily Expand Short URL Using PHP

Tags: ,

Mar 03

This piece of code will allow any user with the capability of ‘moderate_comments’, to include a shortcode within a post comment. If the user does not have this permission, any shortcodes will be displayed as normal text. The code should be placed inside your theme’s functions.php file.

This is useful when combined with affiliate marketing plugins that allow you to display a clickable ad using a shortcode. A visitor to your site might post a comment on an article, requesting a recommendation for a product. You can then reply to their comment, and include a affiliate link or banner ad that advertises the product in question.

For example, you may post an article about Tennis, and a user may request a recommendation for a suitable tennis racket. You can then reply with a recommendation for a racket, with an advertisement for that racket that any user who reads that ad may decide to click.

function filterComments($comments)
{
	$filtered_comments = array();
	foreach ($comments as $comment)
	{
		// if not registered
		if ($comment->user_id == 0)
		{
			$filtered_comments[] = $comment;
		}
		else
		{
			$comment_author = new WP_User($comment->user_id);
			// if has capability 'moderate_comments'
			if ($comment_author->has_cap('moderate_comments'))
			{
				$comment->comment_content = do_shortcode($comment->comment_content);
				$filtered_comments[] = $comment;
			}
			else
			{
				$filtered_comments[] = $comment;
			}
		}
	}
	return $filtered_comments;
}

add_filter( 'comments_array', 'filterComments' );
css.php