我正在使用直接链接并在Twitter上通过弹出窗口实现分享按钮:
<a href="https://twitter.com/intent/tweet?url=<?php echo urlencode(get_permalink());?>&text=<?php echo get_the_title(); ?>&via=username" target="_blank"
在所有疯狂的社交媒体插件中,这是我实现分享按钮最简单、最直接的方法。
然而,当标题中有一个&
符号时,标题将破坏应该显示为状态的文本。我知道需要对标题进行urlencode()
处理,但是这样做会在状态消息中显示特殊字符。
由于在Twitter分享中不需要使用+
来表示空格,我需要将任何&
替换为&
。但是,使用str_replace()
似乎无法实现这一点。像<?php echo str_replace('&', '&', urldecode(get_the_title())); ?>
这样的操作也不起作用。