Get current URL (permalink) without /page/{pagenum}/

You can get the current URL through home_url( $wp->request ).

Try the example below:

global $wp;

// get current url with query string.
$current_url =  home_url( $wp->request ); 

// get the position where '/page.. ' text start.
$pos = strpos($current_url , '/page');

// remove string from the specific postion
$finalurl = substr($current_url,0,$pos);


echo $finalurl;

Leave a Comment