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:

function replace_sidebar_headers()
{
	unregister_sidebar('sidebar-1');
	unregister_sidebar('sidebar-2');

	register_sidebar(
                array(
                        'name' => 'Sidebar 1',
                        'id' => 'sidebar-1',
                        'before_widget' => '<li class="widget %2$s" id="%1$s">',
                        'after_widget' => '</li>',
                        'before_title' => '<div class="widgettitle">',
                        'after_title' => '</div>'
                )
        );

	register_sidebar(
                array(
                        'name' => 'Sidebar 2',
                        'id' => 'sidebar-2',
                        'before_widget' => '<li class="widget %2$s" id="%1$s">',
                        'after_widget' => '</li>',
                        'before_title' => '<div class="widgettitle">',
                        'after_title' => '</div>'
                )
        );
}

add_action('widgets_init', 'replace_sidebar_headers', 11);
 

Tags: ,

Add Your Comments

css.php