How can I get the current url in a wordpress page? I have enabled clean urls, but I want the url without the clean urls. For example
http://example.com/?page_id=1
instead of
http://example.com/my-page
2 Answers
Add the following custom function in functions.php file of your theme to get the page url without the clean urls
function get_page_custom_link() {
global $post;
$link = '';
if ( 'page' == get_option( 'show_on_front' ) && $post->ID == get_option( 'page_on_front' ) )
$link = home_url("https://wordpress.stackexchange.com/");
else
$link = home_url( '?page_id=' . $post->ID );
return $link;
}
And call it in your template as following
<?php echo get_page_custom_link(); ?>
Note : It will not work for other urls( attachments, tags, taxonomy, post etc.)