Josh Kennedy Josh Kennedy - 5 months ago 15
PHP Question

Escape WordPress's HTML characters in the_content();

I'm trying to create a custom Facebook share button on a WordPress theme

<a title="Facebook This" href="http://www.facebook.com/sharer.php?s=100&p[title]=MY%20TITLE%20-%20<?php the_title(); ?>&p[summary]=<?php the_content(); ?>&p[url]=<?php the_permalink(); ?>&p[images][0]=<?php bloginfo('template_url'); ?>/images/logo.png" target="_blank">Facebook This</a>


I have everything working splendidly except that Facebook insists on displaying the HTML characters in the description:

<h3>Intro</h3><p>it shows all the tags here and it won't stop!!!</p>...


It does this with the_excerpt() as well.

Does anyone know a quick way to remove the html tags for this?

Answer

Use Strip tag, deatils on: http://php.net/manual/en/function.strip-tags.php

strip_tags(get_the_excerpt());
Comments