Automatically Capitalize All Product Titles

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

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

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?

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']).

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']));

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....

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

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:

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.

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);

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.

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

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);
}

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.

No, it is not require for b4lly's task