We build custom web applications
to grow your business.

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 to you mysql insert statement
$slug = '" . $this->makeSlug($this->db->escape($value['name']))."', // we are using the name (article title) and convert to slug or URL

foreach ($data['article_description'] as $language_id => $value) {
            $this->db->query("INSERT INTO " . DB_PREFIX . "easy_blog_article_description SET
                article_id = '" . (int)$article_id . "',
                language_id = '" . (int)$language_id . "',
                name = '" . $this->db->escape($value['name']) . "',
                description = '" . $this->db->escape($value['description']) . "',
                intro_text = '" . $this->db->escape($value['intro_text']) . "',
                meta_title = '" . $this->db->escape($value['meta_title']) . "',
                meta_description = '" . $this->db->escape($value['meta_description']) . "',
                meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "',
                slug = '" . $this->makeSlug($this->db->escape($value['name']))."',
                ");
        }

 

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:
http://mywebsite.com/index.php?route=blog/article&slug=my-first-article

Instead of:
http://now4now.com/index.php?route=blog/article&article_id=1

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);
TO
$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;       
}

TO

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');

TO

$this->document->addLink('http://yourwebsite.com/blog/'.$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