yuheijotaki.com

Facebook / Twitter のシェア テキストをURLエンコードする

WordPressにて

<ul>
	<?php
		$single_title = get_the_title();
		$separate = '&nbsp;&#x7C;&nbsp;';
		$site_name = get_bloginfo('name');
		$single_text = $single_title . $separate . $site_name;
		$single_text = urlencode(html_entity_decode($single_text, ENT_COMPAT, 'UTF-8'));
	?>
	<li class="facebook"><a href="http://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>&amp;t=<?php the_title(); ?>&nbsp;&#x7C;&nbsp;<?php bloginfo('name'); ?>" target="_blank">Facebook</a></li>
	<li class="twitter"><a href="http://twitter.com/share?text=<?php echo $single_text; ?>&url=<?php the_permalink(); ?>" rel="nofollow" target="_blank">Twitter</a></li>
</ul>