how can I get pagination link url instead of maked up anchor link? currently I used
<?php next_posts_link(); ?>
<?php previous_posts_link(); ?>
for pagination but it return a
, I want to know is there any way to get just next/prev url?
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityhow can I get pagination link url instead of maked up anchor link? currently I used
<?php next_posts_link(); ?>
<?php previous_posts_link(); ?>
for pagination but it return a
, I want to know is there any way to get just next/prev url?
If you check out the source, they're both wrappers around *_posts()
, which in turn are wrappers for get_*_posts_page_link()
(where the wildcard indicates either next
or previous
).
For example, next_posts()
will echo or return the escaped URL, depending on the first argument:
$escaped_url = next_posts( false /* Don't echo */ );
next_posts(); // Prints escaped URL
Otherwise you can get the raw URL with get_next_posts_page_link()
and do with it as you wish:
$raw_url = get_next_posts_page_link();
wp_redirect( $raw_url );
// or...
echo esc_url( $raw_url );
There are get_previous_posts_link()
and get_next_posts_link()
, they should do what you want.
http://example.com/page/2
– Amirmasoud
Dec 4 '15 at 16:04
next_posts_link
tells to use these functions when you need the value returned instead of outputted.
– flomei
Dec 4 '15 at 17:48
get_*_posts_page_link()
did the trick
– Amirmasoud
Dec 4 '15 at 18:41