Encoding issue when tweeting website links with punctuation

php
wordpress
tweetbutton

#1

Having an issue on our website at the minute. We have a button to allow users to share our news articles to Twitter. When tweeted it displays summary card and automatically generates the article title as the tweet.

However, if the article title contains punctuation marks such as apostrophes or quotation marks it displays HTML character codes instead. For example, see this post…

I’m wondering if there is a way to automatically translate these codes to the correct characters to prevent people from tweeting things that are not legible.

Any help would be hugely appreciated.

The code I use for our Twitter button is…

<a class="twitter-share-button" href="<?php echo get_the_permalink(); ?>?text=<?php echo urlencode( get_the_title() ); ?>" data-via="ThisIsArdee"
 data-related="ThisIsArdee">Tweet</a>

#2

Hi there! Have you tried using rawurlencode()? http://php.net/manual/en/function.rawurlencode.php


#3

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.