Gui
Gui

Reputation: 115

Plugin WordPress: basic hypertext link PHP

I'm beginning in PHP/WordPress development, and I am trying to build a little plugin.

In my administration page, I want to make a link so that people can click on it and go to another page, mypage.php for example.

I tried different things, like:

<a href="mypage.php">Click on my page</a>

And a few other variants, but still I get the same error, 404 page not found. Maybe I could do it with a submenu_page, but I still don't know how to make the link with this kind of page.

My problem is probably very basic, but I have no idea how to solve it and I couldn't find an answer to my specific case, so how can I fix it?

Upvotes: 0

Views: 130

Answers (4)

Gui
Gui

Reputation: 115

The solution of my problem is to make a submenu page and to make a link to this submenu. I created a file myplugin.php and a file mypage.php in a folder myplugin. Here is the code to write in myplugin.php:

add_action('admin_menu','main_page');

function main_page(){
        add_menu_page('Plugin de test','Test','manage_options','test','sub_page');
    }

function sub_page(){
        ?>
        <h1> Ma page pour tester les liens <h1> </br> </br>
        <a href="admin.php?page=myplugin/mypage.php">Click here to see!!</a>&nbsp;
        <?php
    }
add_action( 'admin_menu', 'my_plugin_menu' );

function my_plugin_menu() {
        add_submenu_page(NULL, 'page title', 'menu title', 'read', 'myplugin/mypage.php' );
    }

Thank you all for your help, especially Tarun Mahashwari

Upvotes: 0

Durga Prasad Kundu
Durga Prasad Kundu

Reputation: 51

If your mypage.php is present within your website then try to do

<a href="/mypage.php/"> click on my page </a>

And if mypage.php is a page of another website then try to change your code to:

<a href="http://yourdomain.com/mypage.php/"> click on my page </a>

Upvotes: 0

Tarun Mahashwari
Tarun Mahashwari

Reputation: 358

It looks like you need to add a link in the WordPress admin menu at the backend for your plugin. Here is a very simple example to do this.

It will create a sub-level menu item under the Settings top-level menu, and when selected, that menu item will cause a very basic screen to display. Note: this code should be added to a main plugin PHP file or a separate PHP include file.

<?php
    /** Step 2 (from text above). */
    add_action( 'admin_menu', 'my_plugin_menu' );

    /** Step 1. */
    function my_plugin_menu() {
        add_options_page( 'My Plugin Options', 'My Plugin', 'manage_options', 'my-unique-identifier', 'my_plugin_options' );
    }

    /** Step 3. */
    function my_plugin_options() {
        if ( !current_user_can( 'manage_options' ) )  {
            wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
        }
        echo '<div class="wrap">';
        echo '<p>Here is where the form would go if I actually had options.</p>';
        echo '</div>';
    }
?>

Please see the link https://codex.wordpress.org/Administration_Menus for more detailed information.

Upvotes: 1

Oh boy do I try
Oh boy do I try

Reputation: 43

<a href="mypage.php"> click on my page </a>

This will only work if mypage.php is in the same directory as the page that the link is on.

If mypage.php is in a subfolder of the directory of the current page, you use:

<a href="subfolder/mypage.php"> click on my page </a>

If mypage.php is in a different directory, you will have to navigate to it.

<a href="../../superfolder/subfolder/mypage.php"> click on my page </a>

../ means you go up one folder in the directory tree. So in this example you go up 2 folders, then go into superfolder, then go into subfolder, where mypage.php is located.

You can also make a root relative link, which is formatted as follows:

<a href ="/subfolder/mypage.php"> click on my page </a></a>

The leading slash means the root of your websites directory tree, or the top most folder. Then navigate down into a subfolder, where you find mypage.php.

Upvotes: 1

Related Questions