Hitmag Social Sharing not stripping HTML tags from Title
-
Hi,
I noticed that the Hitmag Pro theme (tested it with 1.1.18) does not strip HTML tags from the post Title when it comes to share the post to social networks such as Twitter, Facebook & more using the built-in Social Sharing feature.
The issue becomes relevant when you install plugins who (properly and legitimately) add HTML tags within the
h1.entry-title
element, such as the “Subtitles” plugin:https://www.ads-software.com/plugins/subtitles/
In very short words, the fix should be to replace the following line within the
/inc/template-tags.php
file:$hm_post_title = str_replace( ' ', '%20', get_the_title() );
with the following:
$hm_post_title = str_replace( ' ', '%20', the_title_attribute('echo=0') );
This workaround will effectively fix the issue for good, as
the_title_attribute('echo=0')
correctly escapes the title and also strips all the HTML tags, which is definitely a good practice for a social sharing feature (for the post title, at least). Therefore, I strongly suggest you guys to apply that fix in your Hitmag and Hitmag Pro themes.For additional info regarding
get_the_title()
andthe_title_attribute()
WordPress functions, take a look at the following URLs:- https://github.com/wecobble/Subtitles#theres-weird-html-showing-up-on-my-site
- https://pippinsplugins.com/use-the_title-and-the_title_attribute-correctly/
[ Redacted ]
I sincerely hope that this post will help other developers like me who will stumble upon this issue!
- This topic was modified 6 years, 7 months ago by .
- This topic was modified 6 years, 7 months ago by . Reason: Syntax highlighting
- This topic was modified 6 years, 7 months ago by .
- This topic was modified 6 years, 7 months ago by .
The page I need help with: [log in to see the link]
- The topic ‘Hitmag Social Sharing not stripping HTML tags from Title’ is closed to new replies.