Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

Hitmag Social Sharing not stripping HTML tags from Title

$
0
0

Replies: 0

Hi,

I noticed that both Hitmag and Hitmag Pro (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.

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://wordpress.org/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’, get_the_title_attribute() );

This workaround will effectively fix the issue for good, as get_the_title_attribute() 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() and get_the_title_attribute() WordPress functions, take a look at the following URLs:

Here’s a link to the article I made on my blog (which proudly uses Hitmag Pro with this tweak, BTW) to better explain this workaround:

https://www.ryadel.com/en/wordpress-escape-strip-html-tags-from-post-title-attribute/

I sincerely hope that this post will help other developers like me who will stumble upon this issue!


Viewing all articles
Browse latest Browse all 59525

Trending Articles