So I want a blog post but in the center of every blog post I want to split the content and print a custom field attached to the blog post type.

Ie you field called "Blog Quote" and the user will enter "Some sample text here." Then put the body of the post in the standard body text area.

Then in the template I want to have:

<div class="content-first-half"></div>
<div class="quote-field"></div>
<div class="content-second-half"></div>

So the final result on page would look like:

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Incidunt debitis accusantium cupiditate possimus laboriosam corporis officia quas, eaque facere, porro odio sit! Quia consequuntur nemo repellendus, et consectetur, voluptatem voluptates adipisci beatae quidem a cum labore dignissimos tempore officia harum. Doloremque quis cupiditate recusandae hic ad error accusamus voluptate nemo harum fugiat, minima, repellendus non?

Some sample text here.

Autem similique porro quae quis sapiente voluptatibus nam distinctio sit necessitatibus, perferendis esse accusamus dignissimos hic obcaecati laudantium libero enim molestiae eaque perspiciatis quia ipsa soluta voluptates aperiam voluptatem! Ratione aspernatur labore repellat facere officiis consequuntur pariatur sed? Explicabo excepturi neque eligendi provident, molestias distinctio quae maxime ut aperiam numquam reprehenderit qui ea molestiae libero exercitationem doloribus itaque corrupti.

EDIT: I haven't tried anything because I don't know where to begin but I'm thinking maybe I add some php to strip the 1st X amount of characters on the render content and then do the opposite for the second break. That should handle the content, maybe? As far as the custom field, I'm hoping there's a hook that can pull the currently viewed custom field or something? If this is the right direction, any documentation you can point me too would be great.

1 Answer 1


I'd suggest doing it this way to avoid running into problems where you split within a sentence/paragraph.

Try splitting on <p> - then put the first element (first paragraph) into <div class="content-first-half"> and the rest (if any) into <div class="content-second-half"> in your template.

It should be something like this (assuming $content has the html for the post)

$paragraphs = preg_split('/<p/i', $content);
array_shift($paragraphs); // ( remove first empty element
$first_half = '<p' . array_shift($paragraphs);
$second_half = '<p' . implode('<p', $paragraphs);

I chose <p to split on since presumably the content will be formatted into paragraphis with <p> tags - but could have inline styles/classes attached, so you can't split on a <p>.

As far as getting the post's custom field, this should be a good start.

  • thanks, I'll give it a try. I forgot about the default wpautop so it's going to have <p> tags around everything. Good choice I think.
    – o_O
    Commented Nov 2, 2015 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.