Getting the_content WordPress Text Only (Strip Out Image Tags)

Simple, powerful way to strip out any tags you want from the_content() in wordpress, using regex:

Get the_content() in wordpress without image tags:

$content = get_the_content();
$content = preg_replace("/<img[^>]+\>/i", "(image) ", $content); 		  
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;

Get the_content() in wordpress without image and video (iframe) tags:

$content = get_the_content();
$content = preg_replace("/<img[^>]+\>/i", "(image) ", $content); 		
$content = preg_replace("/<iframe[^>]+\>/i", "(video) ", $content);             
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;

Strip out any html tags from the_content() wordpress:

$content = get_the_content();
$content = preg_replace("/<embed[^>]+\>/i", "(embed) ", $content); 		
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
Friday, February 28th, 2014 · Categories: Wordpress Theme Development (Private)


Post Written by Tison Kelley

Tison Kelley, B.S., specializes in User Interface Design and User Experience in enterprise architectures. Nationally, he has worked with the U.S. Navy, Federal Aviation Administration, and the University of San Diego's Institute for Peace & Justice. Regionally, he has worked with McDonald's franchises, SAAB Sensis Corp, Consumer Credit Counseling, C.B. Richard Ellis, Upstate HomeCare and CNY organizations in a wide variety of industries. He is proficient in XHTML, CSS and Javascript development, as well as PHP, and MySQL on the server-side. He has recently exhibited at trade conferences; Gartner Enterprise Content Management in Las Vegas and Search Engine Strategies NYC. Kelley is a native of Syracuse, N.Y. and has a B.S. in Information Studies & Technology from Syracuse University. He was the founding director of a 501c3 organization that has helped donate over $34,000 for multiple sclerosis research.


Comments are closed.



Return to Blog

We will always build beautiful websites that rank high on search engines.

All About Us

Put simply, our work builds organizations. We've worked with organizations in both public & private sectors.
Read more

Contact

2610 S. Salina St.
Syracuse, NY 13205
Mon - Thurs 9am - 3:30pm
315.233.9283
Contact Us

Get Started

Our latest launch paid for itself on the date of the launch. How can your organization change?
Get Started