Custom Web Applications to Grow Your Business

(256) 429-8145

How to Create SEO Friendly URLS in Opencart 2 Easy Blog Simple Blog Model

The Easy Blog Simple blog system created for OpenCart Ecommerce platform is wonderful and easy to install. However, the free version does not come with friendly SEO urls.

Here is a step by step method to achieve this.

1. Create a function in /admin/model/blog/article.php to rewrite the name field or title to slug (your preferred url). This function will create the url when you create a new article

public function makeSlug($option) {       
// remove url characters       
if (isset($option)){           
$slug = iconv('UTF-8', 'ASCII//TRANSLIT', $option);           
$slug = preg_replace("/[^a-zA-Z0-9\/_| -]/", '', $slug);           
$slug = strtolower(trim($slug, '-'));           
$slug = trim($slug);           
$slug = preg_replace("/[\/_| -]+/", '-', $slug);       
return $slug;   

In your addArticle function in admin/model/article.php add the following line
slug = '" . $this->makeSlug($this->db->escape($value['name']))."', // we are using the name (article title) and convert to slug or URL

2. modify your article_description_name table to include a slug column

3. In your controller/blog/blog.php index function on page 102 add the following line
'slug'  => $result['slug'],

4. In your controller/blog/blog.php index function change line 105 to be
'href' => $this->url->link('blog/article', 'slug=' . $result['slug'])

This changes the url on the blog view index page to read like this:

Instead of:

5. In /model/blog/article.php on line 4 in the getArticle function remove
WHERE a.article_id = '".$article_id."' to
WHERE ad.slug = '" . $slug . "'

ALSO add on line 10 the following
'slug'=> $query->row['slug'],

ALSO add ad.slug, in the mysql select statement in the getArticle function

6. In your controller/blog/article.php file on line 62 change
$article_info = $this->model_blog_article->getArticle($article_id);
$article_info = $this->model_blog_article->getArticle($slug);

AlSO change:
if (isset($this->request->get['article_id'])) {           
$article_id = (int)$this->request->get['article_id'];       
} else {           
$article_id = 0;       


if (isset($this->request->get['slug'])) {           
$slug = $this->request->get['slug'];       
} else {           
$slug = 0;       

ALSO, you will need to set your canonical links here so google can follow the right link (around line 107)

Change this

$this->document->addLink($this->url->link('blog/article', 'article_id=' . $this->request->get['article_id']), 'canonical');


$this->document->addLink(''.$slug, 'canonical');

7. Change breadcrumb with new slug url in controller/blog/article.php

8. Open the .htaccess file located in the root of your openCart website and add this Rewrite rule.
RewriteRule ^blog/(.*) index.php?route=blog/article&slug=$1

That is it. Your openCart blog URL is now SEO friendly