Preface: i am not a good coder.
I need to use $post->post_content
to get the raw post so that i can use the EXPLODE php command. But when i do use $post->post_content
, it filters out the tags that are in my post which need to be retained. here is my script. what am i doing wrong? thanks!
<?php
$content = apply_filters('the_content', $post->post_content);
$contents = array_filter(explode("</p>", $content));
foreach ($contents as $content) {
if (strpos($content, '<img') !== false ) {
echo $content;
echo "</p>after image ad";
} else {
echo $content;
echo "</p>";
}
}
?>
I'm basically trying to insert an Ad after any paragraph that only contains an image.
It seems that when you call:
It applies
autop
to split the paragraphs, and also appliesdo_shortcode
on all shortcodes.So you'd better not to call
apply_filters
here, but callwpautop
instead:See: http://codex.wordpress.org/Function_Reference/wpautop