简体   繁体   中英

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

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>')?>

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>'
 )?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM