I’ve been a very content Shopp plugin user for my wife’s webshop based on WordPress and the recent upgrade to the much awaited version 1.1 has made me even more content. I love the way the way the plugin is setup and how it behaves. The only thing I’m not very fond of how it outputs the page titles in the browser title bar.
As a webshop owner you want to have your product name and categories before the actuall site title. Now, Shopp does do exactly that but it also adds ‘Shop’ in front of it, plus it sticks that to the product and category title. Luckily there is a solution.
In your theme functions.php
you need to add a few lines of code.
[php]//Optimizing Shopp pages for SEO
function forsite_seo_shopp_titles ($title,$sep=" — ") {
global $Shopp; // Access the Shopp data structure
$titles = array(); // An array to keep track of the title elements
if (shopp(‘catalog’,’is-category’)) // Build the category page titles
$titles = array($Shopp->Category->name);
if (shopp(‘catalog’,’is-product’)) // Build the product page titles
$titles = array($Shopp->Product->name);
return join($sep,$titles);
}
add_action(‘wp’, ‘forsite_change_titles_on_shopp_pages’);
function forsite_change_titles_on_shopp_pages(){
if ( is_page(‘X’)) {
add_filter(‘wp_title’, ‘forsite_seo_shopp_titles’,11,2);
}
}[/php]
The code is pretty self-explanatory with the inline comments but just in case it’s a bit fuzzy I’ll explain a bit more. The first code harvests the titles of the categories and products and puts them in an array called $titles
which will be returned joined with the separator ($sep
). Now in itself this first function works great, but if we were to use the add_filter
code with just this one function in place we would lose the proper titles on your regular WordPress pages and posts. Not something we want, right?
To make sure this filter is only applied to Shopp related pages, remember Shopp uses one particular page as a base, we need to apply the add_filter
code to only that one page. So, look up the page_id
of that particular code and replace the X with that ID number and you’ll be fixed. The filter will only be applied if we’re on a Shopp related page and that’s exactly how we wanted it.
Leave a Reply