TransWikia.com

How to change the URL of sub menu page?

WordPress Development Asked on November 26, 2021

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');

One Answer

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

Answered by mozboz on November 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP