how to go to other pages of my wordpress plugin

2019-06-03 23:24发布

问题:

I have a function that once is done should open a page called "nexpage.php" at the end of function I have used the following but none of them work.

include works but when I use this,it includes the new page in current page which I do not want, and need to close the current page and open the next page.

     function myfunc(){
           .........
          include "nextpage.php";
           echo "<a href='nextpage.php'>NewPage</a>";   <<does not find it
          include_once "nextpage.php";                << open it in the page so javascript does not work and login wont disappear
           header('Location: nextpage.php');  <<it refresh the page but does not open the nextpage
     }

回答1:

Personally I would put the full link on the page so that there is no confusion on where you want it to go. I would specify the full path instead of the short path of the PHP file.

You can either use these for a Plugin:

echo '<a href="'.plugins_url('PluginFolderName/nextpage.php').'">New Page</a>';

or

echo '<a href="'.plugin_dir_path( __FILE__ ).'/nextpage.php">New Page</a>';

or if Theme

echo '<a href="'.get_template_directory_uri().'/nextpage.php">New Page</a>';

There are other options as well. When creating setting pages for a plugin you can also create an array of submenu's by using add_menu_page() & add_submenu_page() and listing each page with a subpage-slug that you can point to a function or a page based on the name.

Reference:

http://codex.wordpress.org/Function_Reference/add_menu_page http://codex.wordpress.org/Function_Reference/add_submenu_page