Author Topic: Solved category title tags  (Read 2940 times)

mblokdijk

  • Beginner
  • *
  • Posts: 25
Solved category title tags
« on: October 22, 2016, 16:54:42 pm »
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; ?>

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9024
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.4.2
Re: Solved category title tags
« Reply #1 on: October 22, 2016, 20:56:48 pm »
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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3973
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Solved category title tags
« Reply #2 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.

Dog_Guy

  • Jr. Member
  • **
  • Posts: 105
    • Dog walker & Pet Sitting Melbourne
Re: Solved category title tags
« Reply #3 on: October 23, 2016, 11:10:23 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

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3973
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Solved category title tags
« Reply #4 on: October 23, 2016, 21:59:11 pm »
In VM 3, original code is :
Code: [Select]
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
Code: [Select]
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

  • Beginner
  • *
  • Posts: 25
Re: Solved category title tags
« Reply #5 on: October 24, 2016, 15:59:07 pm »
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.

toolhire

  • Beginner
  • *
  • Posts: 1
  • A beginner
Re: Solved category title tags
« Reply #6 on: May 24, 2019, 00:35:36 am »
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