WordPressのthe_title()はurlencodeされていないのでget_the_title()をurlencodeしようねという話
1%の成功は、99%の失敗によって支えられている。失敗シェアイベント”FUCKUPNIGHTS”とは? http://t.co/ilupk1ZfmN
— ıɾnɟıʞoʇ ıʞoʇoɯ (@tokifujp) 2015, 8月 12
結果としてはこんな感じで…
「"」が「”」になっちゃうのはご愛嬌。
こんな感じでオレオレTwitterシェアボタンを作ってたんだけど、どうも良くない。「"」が含まれるタイトルがTwitterシェアのtextにセットされると動かないのだ。当たり前といえば当たり前。
<a class="twitter_btn" href="http://twitter.com/share?text=<?php the_title(); ?>&url=<?php the_permalink(); ?>" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;"><img src="<? echo get_stylesheet_directory_uri(); ?>/images/BtnTwitter.png" width="64px" height="64px" alt="Twitter" /></a>
答え(早い)
echo urlencode(get_the_title());
つまりこうですね。
<a class="twitter_btn" href="http://twitter.com/share?text=<?php echo urlencode(get_the_title()); ?>&url=<?php the_permalink(); ?>" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;"><img src="<? echo get_stylesheet_directory_uri(); ?>/images/BtnTwitter.png" width="64px" height="64px" alt="Twitter" /></a>
そんじゃまた。
WordPress 仕事の現場でサッと使える! デザイン教科書 (Webデザイナー養成講座)
- 作者: 中島真洋 ,ロクナナワークショップ
- 出版社/メーカー: 技術評論社
- 発売日: 2015/06/23
- メディア: 大型本
- この商品を含むブログを見る