Trimming get_next_posts_link in WordPress

I’m using get_next_posts_link() for custom paging controls in a WordPress theme. The problem is, the function returns HTML tags and some description text:

<a href="http://localhost/awebsite/page/2/" >Next Page &raquo;</a>"><span>Next</span>

All I am interested in is the URL. Is there a core function for taking just the URL? Or will I have to perform a bunch of string functions to trim down the stuff I’m returned?

Related posts

Leave a Reply

2 comments

  1. get_next_posts_link() uses an undocumented function get_next_posts_page_link() to return the actual URL, so assuming that the next page exists, you could perhaps use that rather than trying to extract the URL from the return of get_next_posts_link().

  2. Use below function for next and previous URL instead of get_next_posts_link() and get_prev_posts_link

    $next_link = get_permalink(get_adjacent_post(false,'',false));          
    $prev_link = get_permalink(get_adjacent_post(false,'',true));