开发者

How to put PHP code in wordpress pagination function (previous_post_link,next_post_link,etc)?

开发者 https://www.devze.com 2023-03-07 17:07 出处:网络
I want to put PHP code in my pagination: <?php next_post_link(\'%link\',\'<div class=\"nav-next\" title=\"<?php the_title();?>\">Next Post</div>\')?&g开发者_开发技巧t;

I want to put PHP code in my pagination:

<?php next_post_link('%link','<div class="nav-next" title="<?php the_title();?>">Next Post</div>')?&g开发者_开发技巧t;

However, the result is I got a text: "" instead of the real title post when I hover my pagination link.

How to get my php code works inside that wordpress parameter?

Thanks.


There is no need for get_the_title. next_post_link already makes the title of the next post available, via %title

 next_post_link( '%link', '<div class="nav-next" title="%title">Next Post</div>' )


Use string concatenation and get_the_title() which returns the value rather than echoing it:

<?php 
  next_post_link(
           '%link',
           '<div class="nav-next" title="'.get_the_title().'">Next Post</div>'
 )?>
0

精彩评论

暂无评论...
验证码 换一张
取 消