Do any of you know a way to check if the current page is the permalink admin page?
-
4Does this answer your question? How can you check if you are in a particular page in the WP Admin section? For example how can I check if I am in the Users > Your Profile page?– keroCommented Dec 15, 2020 at 10:12
-
What's the problem this is trying to solve? You may not need to know this and use dedicated actions and filters depending on what you're doing– Tom J Nowell ♦Commented Dec 15, 2020 at 12:37
3 Answers
<?php
// 'current_screen' action fires after the current screen has been set
add_action( 'current_screen', 'my_check_current_screen' );
// $current_screen is WP_Screen object passed by the 'current_screen' action
function my_check_current_screen( $current_screen ) {
// compare current screen ID to the string of your choice
if( 'options-permalink' === $current_screen->id ) {
echo 'I am on the "Permalink Settings" screen';
}
}
You can check what you can play with using the 'current_screen'
action instead of global $pagenow
:
add_action( 'current_screen', 'my_print_current_screen_object' );
function my_print_current_screen_object( $current_screen ) {
echo '<pre>';
print_r( $current_screen );
echo '</pre>';
}
Try below lines into your function.
global $pagenow;
echo $pagenow; // This should give you current page of admin page
I don't know exactly what you want to do. But basically, you can use:
is_page( 'contact' ) // To see if this page is the page contact
is_singular( 'post' ) // To see if this is a spefic post type
get_permalink() // To get the permalink of a post inside the loop
global $pagenow // To get the page you are now
If you explain better what you want, it is easier to offer a better answer.