I am using the following function (tried both in my Wordpress Child Theme function file as well as a plugin - works in both cases) to remove hashtags from post titles. The function does what I want but then all titles (post body content is ok just titles) are now showing HTML numbers for characters (i.e., ' = &8217; and & = &038; and - = &8211;).
So this title
That's #testing the & and apostrophe #tagstitle #cats #cat #instagramcats
becomes
That&8217;s testing the &038; and apostrophe
Which removes hashtags as desired but creates the character issue.
function remove_hashtags($string){
return preg_replace('/#(?=[\w-]+)/', '',
preg_replace('/(?:#[\w-]+\s*)+$/', '', $string));
}
add_filter('the_title', 'remove_hashtags');
I've tried adding additional code:
html_entity_decode('the_title', ENT_QUOTES | ENT_XML1, 'UTF-8');
to the function after reading up on PHP (I'm just learning) but it doesn't seem to work and I'm not sure how to use
html_entities($string)
(question update adding more information)
I basically took the code from here - that had exactly what I needed. I just added the last lines for filtering the WordPress Post Titles.
I don't want to make it too complicated a question but ideally I would like to remove the hashtags from the text and actually create post tags from them. I have found several answers for each part I just don't know how to put it all together. Forget that though...I really just want to find out why all of the sudden the ascii numbers are replacing the original punctuation.