For better SEO optimization of products and their categories, sometimes you just need to make a mask so that everything at once has something at the start of the promotion, and then promote a particular product or category, changing tags under requests. The following describes how to quickly make a mask for products and categories.
This method has been tested on OpenCart 22.214.171.124. Work on other versions is not 100% guaranteed and may require modifications.
All changes in this example will writing in module with the standard ocmod mechanism. You can make all changes directly in the engine files, then as you prefer.
Create a module file, as an example, meta_teg_mask.ocmod.xml, which will be located in the /system/ folder. It is in this file will make all changes to the engine.
1. Create special fields in the admin area, in which we will register our mask.
In the language file of the settings page setting.php, located path “admin/language/en-ru/setting/setting.php” we add the name of the future fields under the tags.
In the controller of the settings page setting.php, located path “admin/controller/setting/setting.php”, we define language variables and program initialization and assignment of values to the fields when saving.
In the file of the visual presentation of the settings page setting.tpl, located path “admin/view/template/setting/setting.tpl” we program the output of fields.
As a result, in the settings, in the “Store” tab, the created fields should appear, which, later, we will use for storage the mask of meta tags.
2. Now to assign a mask for categories and products in the controller of the site header.
In the controller, the header of the site header.php, located path “catalog/controller/common/header.php”, make the definition of meta tags.
if(isset($this->request->get[‘route’]) && $this->request->get[‘route’]==’product/category’)
if(isset($this->request->get[‘route’]) && $this->request->get[‘route’] ==’product/product’)
check which page is open – the page of the category or product.
Then for each meta tag we determine if it is not filled in the admin panel, we substitute a mask instead. If it is full, go to the one in the admin panel.
With title, the situation is slightly different. It is always filled when creating a product or category. Therefore, we first check whether the title is the same as the category / product name, and if it’s the same, put the nurse.
As a substitute for the word in the mask on the name of the product / category in this example is used %h1%
$config_mask_meta_title_product = str_replace(“%h1%”, $product_info[“name”], $config_mask_meta_title_product);
You can use your own.
That’s basically all, the result will be
Download module finish file.
If you have any questions, want to get individual advice or you have an interesting offer, you can contact via the feedback form.
Or write to the email firstname.lastname@example.org