Heal Your Church WebSite


Teaching, rebuking, correcting & training in righteous web design.

How to improve WordPress widget SEO in 2 edits or less

How do you quickly change the default <h2> tags to <h3> on widget sidebar titles without hacking into the core WordPress engine? Glad you asked, as below I’m going to explain techniques I used at blogJordan.com that demonstrate how find what needs to be edited in your current theme, and them some approaches in how to make the edits – including a global search and replace for the brave.

how to improve your wordpress SEO in 2 edits or less

First let me point out, I’m not one of those overnight experts in search engine optimization, more commonly referred to as SEO. In fact, I find myself annoyed with most posts and emails from self-proclaimed SEO experts. Especially when it comes to articles how how to make one’s church and charity website more search engine friendly … as I’ve found not just a little-bit of plagiarism exhibited … but I digress.

What we’re editing

Kvetch aside, judicious use of header tags will not only help smart search engines better identify key blocks of text, similarly will help make your site more accessible – the latter point as expressed in the Dive Into Accessibility Day 27: Using Real Headers.

The former point best described, and resolved by WordPress forum user ‘TammyHart’ of skinetti.com when she responsds to the question ‘changing titles font from h2 to h4 only in the sidebar?‘ with

Google doesn’t know what a sidebar is, but it does know what a high level heading is and putting the word “Categories” in a level 2 heading is not good SEO …

… Changing the theme’s functions.php … is the right way to fix this …

… simply edit your sidebar.php where it gives the code for the bookmarks like this:
<?php wp_list_bookmarks('title_before=<h4>&title_after=</h4>'); ?>

The Easy way

Given Tammy’s great advice, the easiest to implement this change for a novice (using WordPress 2.5 or greater – using an up-to-date theme) is to:

  1. click on the “Design” menu tab,
  2. then the “Theme Editor” sub menu option,
  3. then selecting the sidebar.php file,

Make your edits, hit the “Update File” button and viola your done.

The Geek way

Hey Dean that’s great, but what if my sidebar.php doesn’t directly call the call ‘wp_list_bookmarks‘ function? Glad you asked …

Yes folks, some theme creators will put the call to this WordPress function in the functions.php, or some-custom-sidebar.php they then “include” into their sidebar.php file. In those cases, here’s what you need to do:

Step 1: Find your themes path
The quickest way I find a theme is to use my browser’s “view source” feature and find out where style.css exists … for example:
http://mysite.com/wp-content/themes/mytheme/style.css
Step 2: Putty an SSH session
Putty is a tool that allows one to create a command line session on their web host’s server – and for today’s example, we’re going to assume it’s a Linux-based server.
Step 3: Change Directory to the the path
cd mysite.com/wp-content/themes/mytheme
Step 4: find and list which file contains wp_list_bookmarks
grep “wp_list_bookmarks” *php -i -l
Step 5: edit the file or files

Oh neat trick Dean, but how do I go about editing the file? Glad you asked …

There are two ways, one is direct for a specific file … the other is indirect and can be used to globally replace a string pattern across multiple files across mulitple directories.

Single File:
Using the text editor available on most modern-day Linux distributions, such as nano or pico, open up the file and edit as needed:
cp my-custom-sidebar.php my-custom-sidebar.backup
nano my-custom-sidebar.php
Global Search & Replace
Using a combination of the xarg command with perl – here are two edits you can make that’ll convert all instances of <h2> to <h3> without losing style, class or other attributes:

  1. add parameters to the wp_list_bookmarks function – and please note, the 2nd argument is to be issued as a single command line (despite the word-wrapping):
    ls -1 *php | xargs perl -pi -e 's/(wp_list_bookmarks)\(\s*\)/$1("title_before=\
    &title_after=\<\/h3\>")/gi';
  2. change any other instance of h2 in sidebar to h3
    ls -1 sidebar.php | xargs perl -pi -e 's/<(\/*)h2(.*?)>/<$1h3$2>/gi';

Hey that’s great, so what are the downsides? Glad you asked …

Backup Everything

Please don’t overlook this step … simply enter this command first:

cp sidebar.php sidebar.backup

Also, with the search-and-replace step, be aware you can potentially send your entire site to “h-e-double-toothpicks” in a matter of seconds if you’re not careful (which is why I strongly advise you make backups).

You’ll also note that I limited the range of my edits to the current theme path. Certainly one can recurse all php pages in one’s themes directory piping the following results into your xargs initiative:
find /myroot/mydomain.com/wp-content/themes -name "*.php" | xargs ...
However, before you do that, do me a favor and back everything up:
tar -zcvf mythemebackup.tar.gz /myroot/mydomain.com/wp-content/themes

Recycle your Cache

Also, you may not see these changes take place until you either post a new article – or temporarily turn off (then back on) your cache.

Modify your CSS file

Finally, make sure you’ve got your <h3> (or <h4>, etc …) tags covered in your CSS file. One quick way is simply to find wherever the sidebar <h2> is defined, and add the other header … for example here on HealYourChurchWebsite:
.rsidebar h2 {font-size:14px;border-bottom:dashed 1px #ccc;margin:0 7px 3px;padding:3px 0;}
becomes
.rsidebar h2, h3 {font-size:14px;border-bottom:dashed 1px #ccc;margin:0 7px 3px;padding:3px 0;}

Conclusion

Of course, I tried that with the theme for this site – but the theme is too old – which is why I’m still seeking a replacement for it in the very near future. Still, I got it to work at blogJordan.com and a few others.

So what about you? Got a nifty WordPress SEO trick that will make your church and/or church website more search engine friendly? Don’t be shy, leave a comment in love.

3 Comments

  1. The complexity of this makes me glad I still use MT – no PHP required, just HTML. :-D

    Which reminds me, have you looked at the new MT 4.21? It seems that it has now evolved to a very nice solution for churches since it now includes a basic forum implentation in the Pro package. That package isn’t free for non-profits (it is for individuals), but a 5 author/5,000 profile non-profit license is a reasonable $200.

  2. Pingback: Blog Roundup for 6th of October 2008 :: Christopher Ross

  3. Pingback: Blog Roundup for 7th of October 2008 :: Christopher Ross