You are here:  » Possible to remove psuedo apostrophes from product name - but only in html?


Possible to remove psuedo apostrophes from product name - but only in html?

Submitted by 2fer on Fri, 2014-11-07 22:42 in

Hi David,
I looked around for this answer, the closest I found was node 5230, but it did not have what I'm looking for.

There are items in a few feeds with single quotes ' used as apostrophes: M'Lady or D'Mark which is working fine where the product name is shown, but it cuts short the meta tag for description and img alt contents at the start of the description. The alt tag thing is a bother, but not like the description. I get GWT complaints about "short Descriptions" when there is plenty of text but I can see that it isn't being read after the first ' in the description text. I know how to remove it from the name with filters but was wondering if there is way not to end up with M Lady or MLady shown in the product name? If not, I'll just remove the ' from the name, but I thought I'd ask.

Thanks!

Submitted by support on Sat, 2014-11-08 09:12

Hello 2fer,

HTML meta tag content fields should be output using htmlspecialchars() by html/header.php but this may have been changed from the distribution on your site - I know you have been using the script for some time. If you could check in that file, and see if perhaps the meta tags are being output without this processing, for example:

<meta name='<?php print $name?>' content='<?php print $content?>' />

That should be:

<meta name='<?php print $name?>' content='<?php print htmlspecialchars($content,ENT_QUOTES,$config_charset); ?>' />

...and descriptions will then be unaffected by the use of single-quotes in the text.

Similarly, the img alt tags are also processed with htmlspecialchars() in the distribution, so if you could also check where you might have in html/product.php (13/03A) -

alt='<?php print $mainProduct["name"]; ?>'

...and REPLACE with:

alt='<?php print htmlspecialchars($mainProduct["name"],ENT_QUOTES,$config_charset); ?>'

And similarly in html/searchresults.php> and html/featured.php>. If all looks OK or you're not sure how to apply the changes, if you could post your current code surrounding the meta / alt tags within your html/ files, I'll double check for you and advise how to modify accordingly..

Cheers,
David.
--
PriceTapestry.com

Submitted by 2fer on Sat, 2014-11-08 17:29

Thank you David,
Without even looking, I'm sure that is what is in there. I've been customizing the templates so I'm just now adding those changes to some older shops. This looks like what I needed. I sure appreciate your help!
Thanks!
2fer

Submitted by 2fer on Sat, 2014-11-08 23:12

Hi David,
They're all fixed now. Just one thing - the alt tags did not have the text shown to find, so when nothing was found I looked through the code for the alt= after the images and found
alt='

<?php
 
print $product["name"]; 
?>
'
instead of
alt='
<?php
 
print $mainProduct["name"]; 
?>
' so I searched with Multi-file search and then they showed up in all the searchresults.php files. I checked product.php and they already had been changed. Probably some issue you fixed way back when. I checked a few that had been problems and they were coded with the ' html entity now.
Thanks again!
2fer.