I am trying to customize the output of the previous post link.
I want to display 2 titles (with link) for the previous post, one should be a custom text and other should be title of post, for example:
Read Previous This is Post tile.
Both of them should link to the previous post
I am trying following code, but it displays both titles as ‘Read Previous’.
<?php previous_post_link('
<div class="prev-post">
<span class="title1">
<h5>%link</h5>
</span>
<span class="title2">
<h5>%link</h5>
</span>
</div>
', __('Read Previous', 'domain')
); ?>
I would just filter
previous_post_link
andnext_post_link
. This way, your template stays clean, and you move the extra logic to thefunctions.php
.Example, not tested:
Of course it is the same. Why would you think that that same placeholder–
%link
— would be replaced by different strings? Only one of which you’ve provided?The
previous_posts_link()
function is not meant to take multiple placeholders anyway. You aren’t going to be able to do this the way you are trying to.The simplest thing to do is pass the post title in the string:
In fact, I don’t see a filter that would let you do it any other way.