PHP在Wordpress中无法对IE中生成的标题进行编码/解码(删除/更改引号)


PHP in Wordpress won't encode/decode generated title in IE (remove/change quotation marks)

所以,我们的网站有可以在Twitter和Facebook上分享的新闻故事。在FF和Chrome,推特链接工作良好,没有问题。然而,IE决定不喜欢引号,每次我们试图通过我们的网站分享一个有引号的故事时,它都会发送一个HTML 400错误请求。具体的断裂与the_title()有关,而与the_permalink()无关。

有问题的代码段:

<a href="https://twitter.com/home?status=<?php the_title(); ?> - <?php the_permalink(); ?>" target="_blank" onclick="return !window.open(this.href, 'Share on Twitter', 'width=500,height=500')"><img src="<?php echo get_template_directory_uri(); ?>/img/share-tw1.png" width="28" height="28" /></a>

我试过把the_title()包裹在父母和应用urlencodehtmlspecialchars或其他类似的东西,没有运气编码生成的URL。(它根据故事的标题和链接到它的URL生成)。

谁能帮助或提供洞察力,需要发生什么,以使IE接受引号?

我会尝试使用esc_url(),使用返回标题(这意味着您需要将get_the_title()传递给esc_url())。

?status=<?php echo esc_url( get_the_title() ); ?>