You can get the current URL through home_url( $wp->request )
. Try the example below:
1 2 3 4 5 6 7 8 9 10 11 12 13 | 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; |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.