top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to add a menu page when activating a custom plugin in Wordpress?

0 votes
346 views

I am making a custom plugin for wordpress and i need to create a page in the admin menu. I already have a file called menu_list.php with the following code:

function jps_mail_list_page_entry() {
add_menu_page(
    __('JPS Mailing List'),
    'JPS Mailing List',
    'manage_options',
    'jpsNews_mailinglist',
    'jpsNews_mailing_list',
    'dashicons-email'
);
}
add_action('admin_menu', 'jps_mail_list_page_entry');

function jpsNews_mailing_list() {
    echo 'hello';
}

Now, in the plugin page i have this:

function jpsNews_activate_plugin() {
    include_once(plugin_dir_path(__FILE__).'pages/mailing-list.php');
}
register_activation_hook(__FILE__,'jpsNews_activate_plugin');

Its not working. How can i do it?

posted May 26, 2017 by Saheb Pro

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Turns out the function to add the pages must be outside the other functions. Just put theme at the end of the script outside the activation hook and it work.

// DISPLAY PAGES AND SUBPAGES
function jps_mail_list_page_entry() {
    add_menu_page(
        __('JPS Mailing List'),
        'JPS Mailing List',
        'manage_options',
        'jpsNews_mailinglist',
        'jpsNews_mailing_list',
       'dashicons-email'
    );
}
add_action('admin_menu', 'jps_mail_list_page_entry');

function jpsNews_mailing_list() {
    include_once(plugin_dir_path( __FILE__ ) . 'pages/mailing-list.php');
}
answer Jun 1, 2017 by Ankana Guchait
Similar Questions
0 votes

I want to create a separate custom 404 page for my wordpress site that when 404 error occurs then that page will be display. I create a 404 page but when I tried to test it, the 404 page of the root site appears. Can anybody help me?

0 votes

I am working on a site which is built on Wordpress, and having two menu, primary menu and secondary menu. I want to merge this two menu in theme and make it in a single list.

How can I merge this two menu into single list? Can anyone help me?

0 votes

I just created a custom theme for my wordpress project inside my wp-content/themes/mycustomtheme, I added an index.php and a style.css file to the new theme but when I go to themes in my dashboard the newly created theme is not shown as an option. What else am I missing? Can anybody help me?
This is my style.css

/*
Theme Name: Start WordPress
Theme URI: http://wordpress.org/themes/startwordpress
Author: Me
Author URI: http://wordpress.org/
Description: The Start WordPress theme is my first custom theme.
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: bootstrap, black, brown, orange, tan, white, yellow, light, one-
column, two-columns, right-sidebar, flexible-width, custom-header, 
custom-menu, editor-style, featured-images, microformats, post-
formats, rtl-language-support, sticky-post, translation-ready
Text Domain: startwordpress

This theme, like WordPress, is licensed under the GPL .
Use it to make something cool, have fun, and share what you've learned   
with others.
*/
...