News:

Looking for documentation? Take a look on our wiki

Main Menu

Solved category title tags

Started by mblokdijk, October 22, 2016, 16:54:42 PM

Previous topic - Next topic

mblokdijk

I had a problem with the category <title> tags. i wanted them to be the title tags that i enter in the category edit field. (meta-title) but this is the meta-title tag in the html that is outputted..The title tag was the name of the first category.

Not SEO friendly at all. i solved it with the following code, below the </head> in my template's index.php

if the meta-title is filled it takes that, and if not, the name of the category instead. Hope it helps some one! (be sure to change the table_name (josyh_virtuemart_categories_nl_nl ) to your own table name)

<?php if (JRequest::getVar('view')=='category') : // custom title-tag for the vm categories ?>
   
    <?php

      $category_id  = vRequest::getVar ('virtuemart_category_id', 0);
      $query = "SELECT customtitle FROM josyh_virtuemart_categories_nl_nl WHERE virtuemart_category_id = ".$category_id."";
      $db = & JFactory::getDBO(); $db->setQuery( $query );
      $page_title = $db->loadResult();

      if(empty($page_title)) {

         $query = "SELECT category_name FROM josyh_virtuemart_categories_nl_nl WHERE virtuemart_category_id = ".$category_id."";
         $db = & JFactory::getDBO(); $db->setQuery( $query );
         $page_title = $db->loadResult();
       }

      /*$this->setTitle( $page_title . ' - ' . $app->getCfg( 'sitename' ) );*/
      $this->setTitle( $page_title );
   
   ?>
    <?php endif; ?>
Passionate Joomla webdeveloper from the Netherlands, please checkout jmodules.com

GJC Web Design

but it should already take the enrted meta title ..

what versions are u discussing?

the title tags rendering is done in the VM view category->view.html.php towards the bottom and the code is similar to your fix
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Studio 42

I think you use a very old Joomla and VM release ???
Most of your code is obselete ! ;)
I think all this is solved in VM3 and vm 2.6.

Dog_Guy

Quote from: Studio 42 on October 23, 2016, 00:28:51 AM
I think you use a very old Joomla and VM release ???
Most of your code is obselete ! ;)
I think all this is solved in VM3 and vm 2.6.


Hi Studio -   as per my msg.  3.0.16  IS still broken for this specific bug, which is my current VM and seeing that newest releases can have bugs I wasnt going to upgrade to find out if the bug had been fixed and bring more bugs in.

THOUGH here is the big tip for the day.   Some of my developers had no idea about it, and others said they were too busy to find a solution.  I spent a lot of time and some money to find a solution that was ridiculously simple.

While you can put meta title data into the VM 3.0.16 edit fields for individual products and they ARE used in the browser title as is the plan, the Category meta data IS NOT.   Of course since the Categories are typically also replicated as MENU links on an ecommerce site you can just go into each Menu link you want to add your own seo title to and do it from there instead.  I think that when VM category metadata fields work (future releases) they will probably over-ride the MENU category data ...  so I just have to make sure that only the MENU data is filled in, or keep the data in the VM category fields exactly the same.

NOTE the only concern I had was that I have four or so menu's that use category links because of template design ... and have found that if I fill in the MAIN MENU category meta title data it replicates to all of the other MENUs.  As long as the Category words are the same which you want to avoid possibility of google considering there are duplicate pages.

ANYWAY.  Hope that helps others out for this short term fix.  NO core code hack, and actually using the JOOMLA field positions rather than the nice to have VM ones that didnt work in the version I (and the original poster) had.
You can buy healthy dog treats from either of my sites: http://www.dogwalkersmelbourne.com.au/ or http://www.healthydogtreats.com.au/

Studio 42

In VM 3, original code is :
if (!empty($category->customtitle)) {
        $title = strip_tags($category->customtitle);
      } elseif (!empty($category->category_name)) {
      $title = strip_tags($category->category_name);
} else {
$title = $this->setTitleByJMenu($app);
}

$title = vmText::_($title);

So it do exactly what you have do using 2 queries more.
If you need to change this then you can use for eg in JOOMLAROOT\components\com_virtuemart\views\category\tmpl\default.php
with $this->category
if (!empty( $this->category->customtitle)) {
        $title = strip_tags( $this->category->customtitle);
      } else {
      $title = strip_tags($this->category->category_name);
}
$document = JFactory::getDocument();
$document->setTitle( $title );


Note: code was not tested, but i doubt that the Core code is not SEO ?


mblokdijk

Hello to you all.

its vm3 and joomla 3. nothing obsolete!

the <title></title> tag is way more SEO important then the meta-title tag.

the title tag is now entirely adjustable per category, instead of taking the default category name, or parent category name.
Passionate Joomla webdeveloper from the Netherlands, please checkout jmodules.com

toolhire

Very well, your solution helped me, I spent hours looking for a solution to this problem and your solution has helped me. Thank you!.

I do not know if it would be possible to extend this code so that it also obtained the meta description of the category, although the title is already correct, I still see the meta description of the parent category.

Thank you. ;D