douhui1630 2015-10-09 20:24
浏览 51
已采纳

Wordpress中的PHP不会在IE中编码/解码生成的标题(删除/更改引号)

So, our site has news stories that can be shared in Twitter and Facebook. In both FF and Chrome, the twitter link works fine, no problem. However, IE decided that it doesn't like the quotation marks and will send an HTML 400 Bad Request every time we try to share a story via our site that has quotation marks inside of it. What breaks in particular is related to the_title() and not the_permalink().

The code section in question:

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

I've tried to wrap the_title() in parens and apply urlencode or htmlspecialchars or anything else like it and have had no luck encoding a generated URL. (It generates based on the title of the story and the URL linking to it).

Can anyone help or provide insight as to what needs to happen in order for IE to accept quotation marks?

  • 写回答

1条回答 默认 最新

  • dongqu4443 2015-10-09 20:29
    关注

    I would try using esc_url(), using the returned title (which means you need to pass get_the_title() to esc_url()).

    ?status=<?php echo esc_url( get_the_title() ); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?