X

How to Add Post Divider in Between Two Posts or More

Snippets by IsItWP

Are you looking for a way to auto insert a post divider “div” that you can style using the “post-item-divider” class? While there’s probably a plugin for this, we have created a quick code snippet that you can use to add post divider in between two posts or more in WordPress.

Instructions:

All you have to do is add this code to your theme’s single.php file before the loop:

<?php
if (($wp_query->current_post + 1) < ($wp_query->post_count)) {
   echo '<div class="post-item-divider">Post Divider</div>';
}
?>

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 62 best free WordPress blog themes and how to create a WordPress donation form.

Comments   Leave a Reply

  1. Mens Fragrances May 23, 2012 at 6:15 am

    I like these all watch style.Thanks for sharing this post.

    1.  no problem glad that I could help

  2. For a blog to be
    successful it needs to be well written, frequently updated, well designed and
    honest.Well i liked your tips.Thanks for sharing.

  3. Bargain Perfume May 23, 2012 at 3:17 am

    Great Blog. I add
    this Blog to my bookmarks.

  4. Your way of presentation is really too good. I
    am totally impressed by your post. I am looking for your more updates. Keep
    them coming

  5. Great and excellent explained article.Really very descriptive.Many Thanks for sharing such article.

  6. Among the different popular accessories laptop stand has gained high popularity.Really its amazing.I like this content.I like this post.Thanks to share this blog.

  7. Payday Loan Company March 30, 2012 at 7:30 am

    Well its good to
    read your article.Its a great shared information.I liked the conversation of
    you guys as well.Thanks for sharing.Keep sharing as like this always.

  8. This is my first time reading this blog. Definitely won’t be my last though, really enjoyed it.Thank you for the article. Exactly what I was looking for!

  9. Luckily I found this, very confusion in this before I found this, now it’s clear….

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!