views:

338

answers:

3

In my theme I'm trying to display the excerpts or teasers of child pages, yet I do not want to display any images, I want image tags stripped out.

Once I've gotten the teaser in all its html glory in a php variable, how do I strip out the img tags prior to using echo?

A: 

You probably want to use the semantics of in your pages, similar to how post excerpts work. You can get the list of subpages http://codex.wordpress.org/Template_Tags/wp_list_pages from here and then iterate over them (the above document has an example for styling the names of pages). you can then get the page contents with a custom function and do whatever you want with it.

http://www.mattvarone.com/wordpress/functionsphp-wordpress-themes/

That url explains how to add your own custom functions to a given theme.

Joshua Smith
I already have the content of the posts using a custom function. The problem is I have html content in a php variable, and if the first thing in that post is a giant image, my blog would end up looking broken when that excerpt is displayed as a huge image after I call echo
Tom J Nowell
Sorry, I didn't answer the question you asked. There is an answer that uses regex above, which is an acceptable solution. There is a function in the php language, strip_tags, http://php.net/manual/en/function.strip-tags.php that provides basic sanitization (you can specify a list of allowed tags). You can also use a real parser for XHTML.
Joshua Smith
+1  A: 

And after you got the content in a html variable a small regular expression should do the rest

$content = preg_replace("/<img(.*?)>/si", "", $content);

Should do the trick

tDo
A: 

You could use the the_excerpt() which automatically grabs just the text or you can use a more sophisticated version of the same thing called The Excerpt Reloaded

Paul Sheldrake