Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   WP Shortcode to implement 'Next Page' link (https://www.warriorforum.com/programming/1224317-wp-shortcode-implement-next-page-link.html)

newbie_warrior 10th October 2016 11:54 AM

WP Shortcode to implement 'Next Page' link
 
Any WP programmer experts here know how or where I can find resources to implement
a short code that it will generate an automatic "Next Page" link on a post?

ex. shortcode
[nextpage][/nextpage]

generates:
Next Page >>

current WP site resources are a little complicated for me right now.

Thank you!

Nathan K 26th October 2016 04:08 PM

Re: WP Shortcode to implement 'Next Page' link
 
You dont need to add the closing tag
[nextpage]
To use the title of the post instead of 'Next Page' use
[nextpage title='true']

Paste the following codes in functions.php file.

function shortcode_next_page($atts){
$a = shortcode_atts( array(
'title' => 'title',
), $atts );

$next_post = get_next_post();

if($a['title'] == 'true'){
if (!empty( $next_post ))
return '<a href="'. get_permalink( $next_post->ID ) .'">' . $next_post->post_title . ' &raquo;&raquo;</a>';
}else{
if (!empty( $next_post ))
return '<a href="'. get_permalink( $next_post->ID ) .'">Next Page &raquo;&raquo;</a>';
}
}

add_shortcode('nextpage', 'shortcode_next_page' );


All times are GMT -6. The time now is 10:29 PM.