1

I want to remove the images, regular text, and block quotes from my Wordpress posts so I can place them in different areas on my single.php.

I currently have code which pulls out the images

<?php
preg_match_all('/(<img [^>]*>)/', get_the_content(), $images);
for( $i=0; isset($images[1]) && $i < count($images[1]); $i++ ) {
echo $images[1][$i];
}
?>

and will put only the images there. I need to have similar code which pulls out the block quote(s) and only puts that, and one for regular < p > text.

Or if there is an easier way to do such a thing.

user3550879
  • 3,389
  • 6
  • 33
  • 62
  • 1
    I would recommend using Advanced Custom Fields for these kind of things. It is a lot easier to create fields and retrieve those than trying to parse the content for data. Look it up! – marqs Jun 06 '15 at 06:49
  • [Looks like someones trying to parse HTML with regex.](http://stackoverflow.com/a/1732454/4689736) You need really need a stack to do this, regex doesn't cut it. – thodic Jun 06 '15 at 08:40
  • I don't want to use a plugin, I managed to get the images to work, and one to put the text. Problem is it puts ALL the text. the content I want to move around is all in the_content and I don't want a new custom field for each post. The code takes out all the images on each post for every page, so I don't have to do anything, especially when I make a new post – user3550879 Jun 06 '15 at 09:34

0 Answers0