Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting current page url on wp-admin/admin dashboard?

Im trying to get the current page url while on the wp-admin/admin dashboard, is it possible?

Im trying to use these codes but i can't seem to get it to work.

global $wp;
$current_page = add_query_arg( $wp->query_vars, home_url( $wp->request ) );

The output i wanted is like this: https://example.com/1/wp-admin/admin.php?page=test But instead, the output turns like this: /1/wp-admin/admin.php?page=test&=https://example.com/1

Any help is greatly appreciated

like image 303
Amenadiel Avatar asked Jun 10 '26 21:06

Amenadiel


1 Answers

To retrieve the URL of the admin area of your wordpress site, you can use admin_url(): https://developer.wordpress.org/reference/functions/admin_url/

It accepts a path. So you could do admin_url('admin.php?page=test'); if you like to hard code. But you want to have it dynamically I guess.

I assume, your page is part of the admin menu. Every menu page automatically has a page parameter in the URL like page=test.

You want to get the URL of the current page you are looking at, so you can get the page parameter from the URL using $_GET.

Putting all this information together, your code can look like:

$current_page = admin_url( "admin.php?page=".$_GET["page"] );

like image 140
rank Avatar answered Jun 12 '26 11:06

rank



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!