Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Automatically Capitalize All Product Titles Rate Topic   - - - - -

 
  • b4lly
  • Junior Member
  • Members
  • Join Date: 29-Oct 08
  • 81 posts

Posted 11 September 2018 - 02:03 AM #1

Hi, hoping someone can help...

 

All my product titles are currently in all lowercase however in google results it doesn't seem to stand out as much as those with capitals.

 

So I was wondering if there is some css code or something that will automatically capitalize all words in my product titles, without me having to manually rewrite every single product?

 

Thanks in advance : )

 

Version 4.2.3



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 18348 posts

Posted 11 September 2018 - 05:25 AM #2

app/controllers/frontend/products.php

 

replace

Registry::get('view')->assign('page_title', $product['page_title']);

with

Registry::get('view')->assign('page_title', strtoupper($product['page_title']));

or use My changes module and products.post.php controller to do it


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • b4lly
  • Junior Member
  • Members
  • Join Date: 29-Oct 08
  • 81 posts

Posted 11 September 2018 - 05:38 AM #3

app/controllers/frontend/products.php

 

replace

Registry::get('view')->assign('page_title', $product['page_title']);

with

Registry::get('view')->assign('page_title', strtoupper($product['page_title']));

or use My changes module and products.post.php controller to do it

 

Thanks a lot for the solution, I'm just wondering though, I only want to capitalize the first letter of each word... so would I need to use "ucwords()" somehow?



 
  • oleg.gorshkov
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 06-Dec 13
  • 3081 posts

Posted 11 September 2018 - 05:41 AM #4

Thanks a lot for the solution, I'm just wondering though, I only want to capitalize the first letter of each word... so would I need to use "ucwords()" somehow?

 

Hello!

 

No, try ucfirst($product['page_title']).


Simtech Development | sales@simtechdev.com | www.simtechdev.com
CERTIFIED CS-CART PARTNER | LICENSES | DEVELOPMENT | ADD-ONS | DESIGN | UPGRADE

Mega SEO Package - All you need for your SEO


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 18348 posts

Posted 11 September 2018 - 01:01 PM #5

Thanks a lot for the solution, I'm just wondering though, I only want to capitalize the first letter of each word... so would I need to use "ucwords()" somehow?

 

Please use

Registry::get('view')->assign('page_title', ucwords($product['page_title']));

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 10952 posts

Posted 11 September 2018 - 09:54 PM #6

ucfirst() only capitalizes the first letter of the string.  For title case, you want to use ucwords().

 

You could also use a css property of:

title {
  text-translation: capitalize;
}

Which would apply to all page titles, not just product pages....


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 18348 posts

Posted 12 September 2018 - 05:32 AM #7

ucfirst yes, but ucwords mentioned in my post transforms each word


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • b4lly
  • Junior Member
  • Members
  • Join Date: 29-Oct 08
  • 81 posts

Posted 14 September 2018 - 03:58 AM #8

 

Please use

Registry::get('view')->assign('page_title', ucwords($product['page_title']));

Thanks, I tried this but discovered that I already have a file products.post.php under My Changes to implement something else. It reads as follows:

 

<?php
 
use Tygh\Registry;
 
if (!defined('BOOTSTRAP')) { die('Access denied'); }
 
if ($mode == 'view' && !empty($_REQUEST['product_id'])) {
$product = Registry::get('view')->getTemplateVars('product');
if(empty($product['page_title'])){
//other data can be added to title dynamic also
$page_title = $product['product'];
Registry::get('view')->assign('page_title', $page_title);   
 
}
}
 
___________________
 
Are you able to tell me how to make the change you suggested in the above code?
 
Really appreciate your time here.
 


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 18348 posts

Posted 14 September 2018 - 06:35 AM #9

Just replace
if(empty($product['page_title'])){
//other data can be added to title dynamic also
$page_title = $product['product'];
Registry::get('view')->assign('page_title', $page_title);   
 
}
with
if(empty($product['page_title'])){
//other data can be added to title dynamic also
$page_title = ucwords($product['product']);
} else {
$page_title = ucwords($product['page_title']);
}
Registry::get('view')->assign('page_title', $page_title);

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • b4lly
  • Junior Member
  • Members
  • Join Date: 29-Oct 08
  • 81 posts

Posted 17 September 2018 - 11:49 PM #10

Just replace

if(empty($product['page_title'])){
//other data can be added to title dynamic also
$page_title = $product['product'];
Registry::get('view')->assign('page_title', $page_title);   
 
}
with
if(empty($product['page_title'])){
//other data can be added to title dynamic also
$page_title = ucwords($product['product']);
} else {
$page_title = ucwords($product['page_title']);
}
Registry::get('view')->assign('page_title', $page_title);

Thanks again for the response.

 

I found no change after making this edit, however was advised by another member to just change the one line to:

$page_title = ucwords(strtolower($product['product']));

...which seems to be working well.

 



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 18348 posts

Posted 18 September 2018 - 05:49 AM #11

 

Just replace

if(empty($product['page_title'])){
//other data can be added to title dynamic also
$page_title = $product['product'];
Registry::get('view')->assign('page_title', $page_title);   
 
}
with
if(empty($product['page_title'])){
//other data can be added to title dynamic also
$page_title = ucwords($product['product']);
} else {
$page_title = ucwords($product['page_title']);
}
Registry::get('view')->assign('page_title', $page_title);

Thanks again for the response.

 

I found no change after making this edit, however was advised by another member to just change the one line to:

$page_title = ucwords(strtolower($product['product']));

...which seems to be working well.

 

 

 

Thank you for the message. Please note that that solution will not capitalise titles generated from product names. Our solution covers it


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • b4lly
  • Junior Member
  • Members
  • Join Date: 29-Oct 08
  • 81 posts

Posted 18 September 2018 - 11:17 PM #12

Thank you for the message. Please note that that solution will not capitalise titles generated from product names. Our solution covers it

 

Yes, I have since added your solution, so we are all good! Thanks again...

if ($mode == 'view' && !empty($_REQUEST['product_id'])) {
    $product = Registry::get('view')->getTemplateVars('product');
    if(empty($product['page_title'])){
        //other data can be added to title dynamic also
        $page_title = ucwords(strtolower($product['product']));
    }
        else {
$page_title = ucwords(strtolower($product['page_title']));
}
        
        Registry::get('view')->assign('page_title', $page_title);
    }


 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 10952 posts

Posted 18 September 2018 - 11:22 PM #13

Woudn't you want to update $product['page_title'] and then re-assign $product also?  While setting $page_title might work for the meta data in that page, other addons or other extensions to the page my reference the $product.page_title value. 

 

All in the name of completeness.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 18348 posts

Posted 19 September 2018 - 06:37 AM #14

No, it is not require for b4lly's task


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.