Insert SEO Keyword automatically in opencart for already inserted products

Hi, today we made the script that inserts the SEO keyword automatically in opencart for already inserted products, the SEO keyword will be the product name. Opencart SEO tips and tricks to insert SEO keyword automatically in opencart for already inserted products, the keyword is the product name.

Once done please don’t forget to delete the seourl.php

You can enable SEO URLs in the OpenCart but inserting the SEO keyword for each product is quite tedious and time-consuming. Some time webmaster imports large data and at this time inserting the SEO keyword by editing each product will take a lot of time. So taking this into consideration we have made a script that takes the product name and replaces the space with dashes (-).

First, download the following zip file:

Then extract is and you just have to upload the “seourl.php” file to the root directory of the Opencart installation, where your admin and catalog folder is and run the following URL http://www.YOURURL.com/seourl.php, with this, it inserts the SEO keywords for the products.

Following is the main codes that play the role

<?php
// Configuration
if (is_file('config.php')) {
	require_once('config.php');
}
require_once(DIR_SYSTEM . 'library/config.php');
require_once(DIR_SYSTEM . 'library/db.php');
require_once(DIR_SYSTEM . 'library/db/mysqli.php');
require_once(DIR_SYSTEM . 'engine/registry.php');
// Registry
$registry = new Registry();
// Config
$config = new Config();
$config->load('default');
$config->load('catalog');
$registry->set('config', $config);
// Database
$db =  new DB($config->get('db_engine'), $config->get('db_hostname'), $config->get('db_username'), $config->get('db_password'), $config->get('db_database'), $config->get('db_port'));
$pi=0;
$pc=0;
$limit="";
if(isset($_GET['limit'])){
    $limit= " limit 0, ".$_GET['limit'];
}
$query = $db->query("select * from " . DB_PREFIX . "product_description" );
$products = $query->rows;

foreach ($products as $product) {
    $pi++;
    $name = $product['name'];
    $name = str_replace("'", '-', strtolower($name));
    $seoname = preg_replace('/s/', '-', $name);
    $seoname = str_replace([':', '\\', '/', '*', ' ','&', "'"], '-', $seoname);
    $seourl = "product_id=" . $product['product_id'];
    $query12 = $db->query("select * from " . DB_PREFIX . "seo_url where query='" . $seourl . "'");
    //echo "<pre>";
    //print_r($query12);
    if (!$query12->row) {
        $db->query("insert into " . DB_PREFIX . "seo_url set query='" . $seourl . "', keyword='" . $seoname . "'");
        echo "<br>Inserted " . $seoname;
        $pc++;
    }
}
echo "<br>Total products ".$pi;
echo "<br>Number of products seo title changed- ".$pc;

It retrieves the name from the product_description table and replace ‘,&,/, space with the dash (-) and check whether the URL already exists and if not then it inserts the SEO keyword. if you need to remove and then just add the replace statement again.

Insert SEO Keyword automatically in opencart
Insert SEO Keyword automatically in opencart

In this way, you can insert the SEO keyword automatically for already inserted products. Please let us know if you have any questions or suggestions, please subscribe to our YouTube Channel for Opencart video tutorials. You can also find us on Twitter and Facebook. Enjoy!

Previous articleWorked, tested Opencart DragonPay Module and its APIs
Next articleOpencart 2 improvement: SEO of home page remove index.php?route=common/home

1 COMMENT

  1. Well, I tried this SEOURL.php in my OC v.1.5.6.5_rc based Installation, and all it did, was writing a “1” on the file page source, telling me, that an error must exist. Nothing else happened, nothing visual on the Page Frontside at all.

LEAVE A REPLY

Please enter your comment!
Please enter your name here