【问题标题】:Issue when tweeting website links with punctuation发布带有标点符号的网站链接时的问题
【发布时间】:2017-12-21 23:13:17
【问题描述】:

目前在我们的网站上遇到问题。我们有一个按钮,允许用户将我们的新闻文章分享到 Twitter。发布推文时,它会显示摘要卡并自动生成文章标题作为推文。

但是,如果文章标题包含标点符号(例如撇号或引号),则会改为显示 HTML 字符代码。例如,看这篇文章...

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

我想知道是否有办法将这些代码自动翻译成正确的字符,以防止人们在推特上发布难以辨认的内容。

任何帮助将不胜感激。

用于我们的 Twitter 按钮的代码是...

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

【问题讨论】:

    标签: php html wordpress twitter social


    【解决方案1】:

    如果您使用the standard Twitter button,您应该能够使用urlencode() 函数解决此问题。看上面的例子。

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

    【讨论】:

    • 嘿@TomaszBakula。谢谢回复。我们已经将它包含在按钮代码中,但它似乎并没有解决它。我已将我们的代码添加到原始帖子中。
    • 以上对我来说很好,但出于某种原因对你来说不是。我建议试试这个urlencode(html_entity_decode(get_the_title(), ENT_COMPAT, 'UTF-8')) - 这是一个解释stackoverflow.com/a/10771778/6160650
    猜你喜欢
    • 1970-01-01
    • 2018-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-06
    • 1970-01-01
    相关资源
    最近更新 更多