Hiding Something in WordPress Until the Last Page of a Post

Using WordPress as a content management system brings you tons of flexibility.  Unfortunately, most of the flexibility is unrealized unless you start diving into some code.  For me, there are certain times when coding is the only way to get things done.  Recently, I ran into a situation where a site I was working on wanted to hide something until the reader reached the last page of a post.  By default, there is no way to do this in WordPress.  Don’t fret, accomplishing this is as easy.

In your theme, you may have a page.php or a single.php file depending on how your theme is set up.  If you don’t have a page.php, you need to edit your single.php file.

Let’s say for instance you wanted to hide the Post Featured Image until the last page of your post.  You would look for this:

<div><!–?<span class="hiddenSpellError" pre="">php</span> the_post_thumbnail(); –></div>

and change it to this

[php]<!–?php if( $page == $<span class="hiddenSpellError" pre="page "–>numpages ) {
<div><!–?php the_post_thumbnail(); –></div>
} ?>[/php]

About Joe D

I have always had a passion for everything computing. In early 2000, I decided to take my passion to the web. Thus, C.O.D. was born. Through the years we have made many great friends at C.O.D. and hope to continue our journey for years to come.

Check Also

Change the WordPress Editor Font

I work with WordPress a lot.  By nature, I like to fiddle with things too.  …