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...

http://www.thisisardee.ie/2017/07/16/shane-finn-meant-raising-e200000-id/

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 is 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>
miken32
  • 42,008
  • 16
  • 111
  • 154
Kelvin Farrell
  • 305
  • 4
  • 21

1 Answers1

1

If you are using the standard Twitter button you should be able to resolve this problem using the urlencode() function. Look at the example above.

<a class="twitter-share-button" href="https://twitter.com/intent/tweet?text=<?php echo urlencode( 'Shane Finn: “If it meant raising €200,000, I’d do it all again”' ); ?>">Tweet</a>
Tomasz Bakula
  • 161
  • 1
  • 7
  • Hey @TomaszBakula. Thanks for the reply. We have that already included in the button code but it doesn't seem to solve it. I've added our code to the original post. – Kelvin Farrell Jul 17 '17 at 13:24
  • 1
    The above works fine for me but for some reason not for you. I would suggest to try this `urlencode(html_entity_decode(get_the_title(), ENT_COMPAT, 'UTF-8'))` - Here is an explanation https://stackoverflow.com/a/10771778/6160650 – Tomasz Bakula Jul 17 '17 at 17:43