admin管理员组

文章数量:1328037

I'm trying to add a sub page under users in admin panel and everything works fine but I have a little problem when clicking on the created page the url changes and refer to my page as query string not new php file

URL : http://localhost/wordpress/wp-admin/users.php?page=filtered.php

and I want : http://localhost/wordpress/wp-admin/filtered.php

is there any way to do so ?

function wporg_options_page(){

    add_submenu_page( 
        'users.php',
        'Filtered Users', 
        'Filtered Users', 
        'manage_options', 
        'filtered.php', 
        'filtered_user_page_html', 
        1 );
}
add_action('admin_menu', 'wporg_options_page');

I'm trying to add a sub page under users in admin panel and everything works fine but I have a little problem when clicking on the created page the url changes and refer to my page as query string not new php file

URL : http://localhost/wordpress/wp-admin/users.php?page=filtered.php

and I want : http://localhost/wordpress/wp-admin/filtered.php

is there any way to do so ?

function wporg_options_page(){

    add_submenu_page( 
        'users.php',
        'Filtered Users', 
        'Filtered Users', 
        'manage_options', 
        'filtered.php', 
        'filtered_user_page_html', 
        1 );
}
add_action('admin_menu', 'wporg_options_page');
Share Improve this question asked Jul 22, 2020 at 13:40 Islam Hanafi MahmoudIslam Hanafi Mahmoud 1616 bronze badges 4
  • You can’t have a URL like that. The admin does not rewrite URLs, so the only way to have that would be to add a filtered.php to the wp-admin directory, which you must not do. You will need to use the normal admin URL format for settings pages. – Jacob Peattie Commented Jul 22, 2020 at 14:30
  • Thanks @JacobPeattie – Islam Hanafi Mahmoud Commented Jul 22, 2020 at 14:36
  • If this is a working page on your site: http://localhost/wordpress/wp-admin/users.php?page=filtered.php And you want that to be accessed with this URL: localhost/wordpress/wp-admin/filtered.php you could do that with rewrite rules. I'm not sure if that's what you want though as perhaps you're trying to have the menu item URL generated differently? – mozboz Commented Jul 22, 2020 at 19:56
  • @mozboz, Yes I want to do so , but I don't know how to use rewrite rules – Islam Hanafi Mahmoud Commented Jul 23, 2020 at 1:37
Add a comment  | 

1 Answer 1

Reset to default 0

As per the requirement in the comments, one way to do that rewrite is with .htaccess. This may be possible with Wordpress rewrite functions too, but I find .htaccess easier as there are some constraints with the Wordpress functions.

If your Wordpress installation is at http://localhost/wordpress then your .htaccess should be in the wordpress directory.

Add this to the top of it to do the rewrite you want:

RewriteEngine On
RewriteRule ^wp-admin/filtered.php(/.*)$ wp-admin/users.php?page=filtered.php$1 [NC,L]

Note:

  • This must be added in your root .htacess file above the start of the Wordpress Rules
  • This will not change the URL in the browser. You can add a redirect if you want it to redirect with e.g. [R=301,NC,L]
  • This is untested but should do what you want or get you close to what you need.
  • As per the comments this is only the URL that you can use to access this page, this won't automatically change any URL's that get rendered in Wordpress

本文标签: wp adminHow to change the URL of sub menu page