Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there a WP function to automatically get the correct URL of the current page? Meaning if I just opened a single post, the function returns the same as get_permalink(), but if I'm on a paginated instance of a page (when paginating through the comments), the function returns the same as get_pagenum_link(get_query_var('paged')) would do.

I've searched the codex but didn't find what I was looking for. (But even get_pagenum_link() isn't documented there.)

I know about this function already, but I would be glad if there was a "native" WP function that does the job.

Thanks in advance! Regards, René

share|improve this question

3 Answers

I dont now of pagination but You can use this function to get url within the loop

<?php $ID = get_the_ID(); 
echo get_permalink( $ID ); ?>

Or else if you dont prefer to use php you can also opt for jquery method here (this will help you to make it work outside the loop)

$(document).ready(function () {
var vhref = $(location).attr('href');
var vTitle = $(this).attr('title');
$('#spnTitle').html('' + vTitle + '');
$('#spnURL').html('' + vhref + '');
});​

or if u prefer to use php function you need to get the id outside the loop

share|improve this answer
Sorry, but this is just not what I've asked for... + the_permalink() doesn't need the id when it's called inside the loop. – René Schubert Feb 1 at 10:04
global $wp;
$current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );

Not a function, but definately using wordpress code..

http://kovshenin.com/2012/current-url-in-wordpress/

share|improve this answer
I'll give this a try, thanks. – René Schubert Feb 1 at 10:01
It works partly, but some things don't work like I want them: Parameters like year are added to the query string, even though they haven't been there before, and other parameters, for example the replytocom parameter, get lost. Do you know a solution for this? – René Schubert Feb 1 at 13:32

wp_guess_url is what you are looking for.

Guess the URL for the site.

Will remove wp-admin links to retrieve only return URLs not in the wp-admin directory.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.