Blog Posts About

WordPress

eCommerce WooCommerce

Importing Products in Multiple Languages Using WPML & WooCommerce Product CSV Import Suite

By default, the WooCommerce Product CSV Import Suite will always import your products in the default language of your eCommerce website. This can be problematic when you are working with a site that has multiple languages.

While WPML is not my language plugin of choice for WordPress, it definitely requires the least amount of work to get running with the WooCommerce ecommerce plugin. It also has several necessary functionalities that make importing products in multiple languages easier than it looks. Here’s my process in more detail.

Import Products in Default Language

A small tip, would be to have all your product images, categories, attributes and tags already uploading into WordPress. I’ve drag-and-drop uploaded over 500 images with no problem, so you shouldn’t have any problems either!

In any case, the first step is to only import the products in the default language of your theme. If you don’t do this, you’ll want to shoot yourself later on. This is relatively easy to do and if you need help working with the CSV either drop a line in the comments or read the official plugin documentation.

Export All Your Products

These easiest way to set up a unique way of detecting what products are in your default language is by exporting them before duplicating. This will allow you to create a function in Excel that can tell you if they are in the default language master sheet or not. This method of ID will only work if you are doing a bilingual site. I’m sure you can figure out a better way if you’re dealing with multiple languages. Please leave the method in the comments if you do!

Duplicate Your Products in Every Other Language

Go to the WPML Translation Dashboard in the Translation Management section. Select all your product posts and scroll down. You should see the option to duplicate the posts for your other languages. Do it as many times as needed. Be sure to have your selection only include posts that have no translation or you may be repeating the same action over and over for nothing.

Merge Proper Text for All Non-Default Languages

This is the last step on your translation journey. Export all your products and use the Excel sheet with your default language products to identity them if needed. Update the relevant information for your translations and merge. Your task is now done!

PHP WordPress

How to Customize WordPress Sidebars

If you haven’t noticed! I’ve not only migrated my domain to t.omlinson.com, but I’ve also created a child theme based off of the Redwood WordPress theme. One particular element I needed to add was different WordPress sidebars based on the category page.

Old Way of Customizing Your Sidebars

In the past, I used to buy HTML themes and convert them into WordPress themes. This avoided some of the bloat found within premium themes and required a much smaller investment. During that era, this is how I would ensure different pages could support different sidebars.

I would create a PHP file called “wordpress-sidebar.php.” Inside, I’d insert the customization that I wanted. I’d usually not use widgets because it wasn’t something I was comfortable with at the time. Afterwards, I’d just add an if statement to call on the file I just created wherever I needed to.

The code would look something like this.

<?php 
 
//if you wanted a custom sidebar for your wordpress category archive page
//you could use in_category() if you wanted to target a post within a category
 
if(is_category("wordpress"){ 
 
      //actually not sure if TEMPLATEPATH is necessary, leave a comment if you know!
 
      include(TEMPLATEPATH . '/wordpress-sidebar.php');
 
      // the else would call the default sidebar, you could use elseif to create a chain if you wanted
 
} else {
 
      // this is a command to get the default sidebar in WordPress
      // it is identical to using include 
 
      get_sidebar();
}
?>

Pretty simple, but it’s the old and wrong way to do it.

New & Better Way to Create Different WordPress Sidebars

You begin by entering into your theme or child theme’s “functions.php” file. You’ll want to add code similar to this one:

<?php 
 
// Basic was of registering new WordPress sidebars
 
if ( function_exists ('register_sidebar')) { 
    register_sidebar ('wordpress_sidebar'); 
 
    // More advanced way of adding an alternative sidebar allow you to control some of the style and CSS
    // elements. You could also use a function called register_sidebars()
    //  to create multiple WordPress sidebars but the function is not recommended. 
 
    register_sidebar( array(
        'name' => __( 'Work Sidebar', $theme_slug), //name that appears in your widget area
        'id' => 'work', //id to call your sidebar this is only variable you must specify
        'description' => __( 'Widgets in this area will be shown on all posts and pages.',  $theme_slug ),
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
	'after_widget'  => '</li>',
	'before_title'  => '<h2 class="widgettitle">',
	'after_title'   => '</h2>',
    ) );
 
// Be sure to replace $theme_slug with your theme's slug! 
 
} 
?>

This will allow you to modify your sidebar using the regular widget section. Next step if similar to the previous way of adding WordPress sidebars, create a file based on the id of your newly registered sidebar. In this case, the file would be named “sidebar-work.php”.

You’ll make whatever modifications you need in that new file and make sure that your dynamic_sidebar(); function refers to your new sidebar by name. If you don’t make changes to that function, your widgets will not show up.

Now, whenever you use the get_sidebar(); function, you can call the work sidebar by doing get_sidebar(‘work’);.

If you need additional help, you should definitely do one of these three things:

  1. Read the WordPress Codex page about customizing your sidebar.
  2. Search the WordPress Development Stack Exchange.
  3. Comment below and I’ll do my best to help you out.
PHP WordPress

Modifying the WordPress Template Hierarchy to Handle Parent Categories

This is essentially plagiarism of a great post by Drew Jaynes. It took me a while to discover his post when trying to figure out how to modify the WordPress template hierarchy so I decided to share it again. Hopefully one of these pages will start to rank better.

Here’s his code with a tiny amount of additional comments:

 
//this code should be pasted into your function.php file
 
function new_subcategory_hierarchy() {  
 
    $category = get_queried_object();
 
    $parent_id = $category->category_parent;
 
    $templates = array();
 
    // preserves the classic WordPress template hierarchy for parent categories
    // or else it create a new path for sub-categories
    if ( $parent_id == 0 ) {
        // Use default values from get_category_template()
        $templates[] = "category-{$category->slug}.php";
        $templates[] = "category-{$category->term_id}.php";
        $templates[] = 'category.php';      
    } else {
        // Create replacement $templates array 
        $parent = get_category( $parent_id );
 
        // Current first
        $templates[] = "category-{$category->slug}.php";
        $templates[] = "category-{$category->term_id}.php";
 
        // Parent second
        $templates[] = "category-{$parent->slug}.php";
        $templates[] = "category-{$parent->term_id}.php";
        $templates[] = 'category.php';  
    }
    return locate_template( $templates );
}
 
add_filter( 'category_template', 'new_subcategory_hierarchy' );

Personally, I find the WordPress Template Hierarchy pretty good. Other than it’s issue with dealing with sub-categories, I’ve never really had a problem with its flow. In fact, I could have easily just copy pasted a template file for each sub-category based on its parent.

Diary WordPress

Merged All My Old Web Properties

I could go on a rant about how I want to create a stronger personal brand, but that would be bullshit.

While doing some spring autumn cleaning, I discovered a few funky files informing me that I’ve been hacked.

I had neglected to update core WordPress, themes and plugins of a lot of my first web projects. I have payed the price for my laziness.

I feel like it will be easier to manage and less risky if I just begin to dump it all my content here.

I had not found a niche that I was particular passionate about. I also hadn’t/haven’t found the willpower to force myself into becoming obsessed about a topic. So I am not too affected by the hack (most of the sites had been abandoned), it’s just pretty annoying to have to half-ass redirect everything late at night.

In any case, there’s a bunch more cleaning to be done in the next few days.

WordPress

How to fix invalid WordPress RSS feed errors

I recently read a great article by Brian Dean about untapped backlink sources. While some are definitely not untapped, I decided to try two of them on Another Marketer. The first source I tapped were blog aggregators. I had no problems submitting my blog feed until I hit Alltop. According to Alltop, I submitted an invalid WordPress RSS feed

I checked the RSS feed on FeedValidator.org and, to my surprise, my feed actually had some syntax errors. I’m not sure why this happened as I touched any of the source files for the WordPress RSS feed and I doubt any of the Bone WordPress theme functions had anything to do with it.

Easy Invalid WordPress RSS Feed Fix

All it needed to do is this:

  1. Navigate to the WordPress Reading Settings
  2. Change how the articles were being displayed from full to summary

Fix invalid WordPress RSS feed errors by selecting a new RSS feed option

I’m really not sure why this worked, but it did. If you’re having the same problems but you’re setting is at summary, try switching it to full instead.

PHP SEO WordPress

Modifying the length of Yoast Breadcrumbs

If you don’t know Yoast’s WordPress SEO Plugin, you’re not a real SEO. Sure, he puts a link in your Sitemap, but it’s a small price to pay for an amazing WordPress plugin.

As a reward for finishing up two posts, I decided to spend some time making some initial design changes to Bones. Most of it was pretty simple. Yet, I did have to pause to fix a minute detail that bugged me about the SEO plugin’s auto-generated breadcrumbs: if the title of a blog post exceeded a certain number of characters, the Yoast Breadcrumbs would take two lines. I decided to take a look at how I could shorten the titles in the breadcrumbs if they went over a certain number of characters.

Getting it to fix on line wasn’t as easy as it looked.

How to Modify the Length of Yoast Breadcumbs in WordPress

The first step is as simple as getting the string that is generated by the plugin as follows.

<?php if ( function_exists('yoast_breadcrumb') ) {
	$yoast = yoast_breadcrumb("","",false);

Then, you just need to create an if statement that takes into consideration the length of the current breadcrumb string. You’ll notice that the length is remarkably long for something that is usually relatively little text. That’s because the breadcrumb string also includes some HTML markup and you’ll have to truncate it all.

You might have to test different lengths depending on the width of your content div.

	if(strlen($yoast) < 585) { ?>
		<p id="breadcrumbs">
			<?php echo $yoast; ?> 
		</p>
	<? } else { ?>
		<p id="breadcrumbs">
			<?php echo substr($yoast, 0, 585)."..."; ?>

As you might of guessed, the last piece of the puzzle is to close the tags that have been cut off by only using a sub-string of $yoast. If you did not select to bold the current page in the breadcrumb options, you can omit </strong>.

			</strong>
			</span>
		</p>
<?php } } ?>
Coding WordPress

Why I chose Bones as my WordPress theme

I often send way too much times shopping for HTML themes on ThemeForest. Before I even get to writing my first post, I’ll have wasted too many hours into not only choosing the theme but developing a WordPress theme based on it.

I have no idea if content is king, but I do know bullshit content. Before I even get to developing my personal WordPress theme, I decided I’d try something different. I’ll just write the content first instead of pouring hours into development. Developing should be a reward if I’m able to consistently produce non-bullshit content.

What’s Bones

Bones is a free responsive WordPress theme based on a mobile-first approach. That’s not why I chose it. I chose it because it not only has extremely detailed code and CSS making it easy to modify for my needs. The code and forks are available on GitHub and it comes loaded with a Sass tutorial.

When I worked at a startup, I started toying with the idea of learning Haml and Ruby on Rails, but never got further than Rails for Zombies. Sass seems like a a good first step towards that goal and it will drastically reduce the time I spend on CSS. Since, I have not started to develop the theme, I haven’t gotten to Sass.

Content comes first so I better get cracking.