At the moment I have it set up so the it’s a span tag above the link that says ‘previous post’ and ‘next post’, the problem is even when there isn’t a next or previous post, the span tag stays there.
<div class="nextprev">
<div class="nex1">
<span>Previous Post</span>
<?php previous_post_link('<strong>%link</strong>'); ?>
</div> <!-- end div nex1 -->
<div class="nex2">
<span>Next Post</span>
<?php next_post_link('<strong>%link</strong>'); ?>
</div> <!-- end div nex1 -->
</div> <!-- end div nextprev -->
How do I put Previous Post inside the php so it only appears when there’s a link to follow?
When using previous_post_link and next_post_link you can allow WordPress to control whether or not the chosen text is displayed.
Like this:
You can replace ‘Previous Post’ and ‘Next Post’ text with whatever you want to show up. Also, you can remove the
<span>tags now. 🙂Edit:
If you’d like to display the title of the post and Previous Post text, try this: