Finding the screen id of a page generated with add_menu_page

I'm at a basic level of WordPress + PHP and I'm trying to build a pretty simple plugin. I've set up the plugin correctly, and the plugin page is generated with function wpplugin_settings_page() { add_menu_page( 'Modal Generator', 'Modal Generator', 'manage_options', 'modal-slug', 'wpplugin_settings_page_markup', 'dashicons-format-gallery', 100 ); } Whereas wpplugin_settings_page_markup is a function that generates my HTML on the plugin page. I copy-pasted a code to create/generate metaboxes and they work great. I can get them to show on posts & pages …
Category: Web

usage of admin_url() in add_menu_page()

Does anybody have experienced this issue: using admin_url() in add_menu_page() returns an url that contains the domain name twice: add_submenu_page( 'smart-crm', __('WP SMART CRM Documents', 'mytextdomain'), __('Documents', 'mytextdomain'), 'manage_options', admin_url('admin.php?page=smart-crm&p=documenti/list.php'), '' ); My output link is : https://domain.com/domain.com/wp-admin/admin.php?page=smart-crm&p=documenti/list.php any idea?
Category: Web

add_menu_page() with different name for first submenu item

The add_menu_page documentation says to pass the menu title as the second parameter: add_menu_page('Page Title', 'Menu Title', ...); When adding more pages later via add_submenu_page, the main page becomes the first entry in the submenu: However, I want the first item in the list to have a different name (but still point to the same page), the way Wordpress itself does it: How could I accomplish that in my plugin?
Category: Web

Pagination in plugin's backend

I am displaying a list of posts in the plugin backend but I can't seem to get the pagination to work. I used the standard approach of getting the "paged" variable and then passing it to get_posts()'s arguments, but whenever I visit my custom backend page or subpage and add the &page=2 variable I get that permissions error about not having enough of them to visit that page. Is there a special way to apply pagination in the backend?
Category: Web

Is it possible to have dynamic post id # in add_menu_page()?

I use the add_menu_page function in my custom theme builds but when I export my local copy of the site and import it in the production site some of post id numbers change and I have to update this function manually (ie: in the code below: ?post=8, ?post=8, ?post=10). Is there a way to have these numbers be dynamic? function custom_admin_menu_links() { $user = wp_get_current_user(); if ( ! $user->has_cap( 'manage_options' ) ) { add_menu_page( 'Home', 'Home', 'edit_posts', 'post.php?post=6&action=edit', '', 'dashicons-admin-home', …
Category: Web

Is there any way to add absolute path for add_menu_page function?

I am creating a plugin for add menu option to WordPress admin and using below function for that: <?php add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); ?> But I would like to add absolute path for menu option in the place of $menu_slug. please see the screen shot, I have created both " Header and footer " using add_menu_page function. I would like to give absolute path for both header and footer. I know plugins are available for …
Category: Web

Hiding Admin Page While Keeping Menu Expanded

I am creating a custom admin section. I have the following code: // Top level menu add_menu_page('Books', 'Books', 'publish_posts', 'books', 'render_books_page', '', 17); // Adding this function to make the first submenu have a different name than the main menu // Details: https://wordpress.stackexchange.com/questions/66498/add-menu-page-with-different-name-for-first-submenu-item add_submenu_page('Books', 'Books', 'All Books', 'publish_posts', 'books', 'render_books_page'); // The Add Book menu page add_submenu_page('Books', 'Add New Book', 'Add Book', 'publish_posts', 'add-book', 'render_add_book_page'); // The Edit Book menu page (this page is hidden from the menu, and accessed …
Category: Web

Custom admin menu order fails if slugs are complicated

I'm not able to reorder WP Admin menu items when pages added with add_menu_page have complicated slugs. At least I think that's the problem... First I create the custom menu items, which is working as expected: function sma_simplify_admin_ui() { global $user_ID; if ( $user_ID != 1 ) { add_menu_page( 'Menu', 'Menu', 'edit_posts', 'nav-menus.php?action=edit&menu=16', '', 'dashicons-menu' ); add_menu_page( 'Memberships', 'Memberships', 'edit_posts', 'edit.php?post_type=wc_user_membership', '', 'dashicons-groups' ); } } add_action( 'admin_init', 'sma_simplify_admin_ui' ); The new items cannot be reordered. If I put the …
Category: Web

Show Custom Taxonomy Inside Custom Menu

I have a custom menu using add_menu_page: add_menu_page('My menu' , 'Some text', 'read', 'nwcm'); Under it, I show a custom post type menu item; // Create the news custom post type register_post_type('nwcm_news', array( 'labels' => array( 'name' => __('News for clients', NWCM_TEXT_DOMAIN) , 'singular_name' => __('News', NWCM_TEXT_DOMAIN) ) , 'public' => true, 'has_archive' => true, 'public' => true, 'show_ui' => true, 'show_in_menu' => 'nwcm', 'taxonomies' => array( 'nwcm_news_category' ) , )); Then I add a custom taxonomy hooked to that …
Category: Web

How to add styles to a submenu page?

I'm relatively new to WordPress and, I am creating this plugin, where I need a submenu page. I have successfully created the main page and have added CSS to it without any problems. However, I came to need a submenu page recently. I used add_submenu_page to create that page, and it worked just fine. As far as I know, I can add as much content to that page as I want, and it won't be a problem, too. The trouble …
Category: Web

The seventh parameter passed to add_submenu_page()

I'm testing WordPress 5.3 (5.3-RC4-46673) with my theme. I have WP_DEBUG enabled. I notice the following error in the dashboard now: Notice: add_submenu_page was called incorrectly. The seventh parameter passed to add_submenu_page() should be an integer representing menu position. Please see Debugging in WordPress for more information. (This message was added in version 5.3.0.) in /app/wp-includes/functions.php on line 4903 There's a related ticket for this error here: Trac Ticket #48249 Troubleshooting The theme I'm using is a child theme. Disabled …
Category: Web

Adding submenu to custom plugin menu page created with add_menu_page() function

I have created a custom menu page using add_menu_page() function. Everything in that page appears as it should in the screen. What I am trying to achieve is adding another submenu under the under the page i previously created(i want it to appear just like when you click on the settings menu in wordpress dashboard). I am pasting a code snippet below: //creating the menu item for the plugin function qpv_custom_menu_link() { add_menu_page( 'Quick Product View Options', 'Quick Product View', …
Category: Web

Where the additonal contents in the expanded menu item come from?

I am studying the header.php for my website, where I find the following codes: <?php if ( has_nav_menu( 'primary-menu' ) ) : ?> <nav class="main-navigation desktop-nav" role="navigation"> <?php wp_nav_menu( array( 'theme_location' => 'primary-menu', 'menu_class' => 'sf-menu desktop-menu', 'container' => false ) ); ?> </nav><!-- desktop-nav --> <?php endif; ?> Based on this, this is to display the navigation menu for desktop version. I then check the HTML source of the real web page, and find the following codes: I know …
Category: Web

meta box on new admin page

I created a new page for the homepage settings of my theme using add_pages_page(). On that page I want to use wp.media to let the user select one or several images from the library (or upload new ones). I thought the way to go was meta boxes but I can't get the box to display. Here's how I tried to add the meta box: function register_homepage_subpage() { add_pages_page( 'Customize Homepage', 'Homepage', 'manage_options', 'my_homepage', 'my_homepage_callback' ); } add_action( 'admin_menu', 'register_homepage_subpage' ); …
Category: Web

Auto add (multiple) Custom Post Types to menu

I'm trying to add custom post types entries automatically as submenu's to my main menu. I've managed to add one CPT "nestjes" by using the code below. Now I would like to add two more CPT's automatically to my menu on the same website: "poezen" and "katers". How do I blend in these variables in the code below? my_theme_poezen_menu_filter poezen-parent-item poezen-post-type my_theme_katers_menu_filter katers-parent-item katers-post-type Thank you for the help. add_filter( 'wp_get_nav_menu_items', 'my_theme_nestjes_menu_filter',10, 3 ); function my_theme_nestjes_menu_filter( $items, $menu, $args ) …
Category: Web

Add custom page link with anchor

In my admin section I would like to add in Appearance > Menus > some custom pages to add to my menu. I have two different menu one for the home page and one for the others pages. In my home page menu I add the menu elements as link because I need to give to the href the id of html element so i can 'redirect' in a specific point in my page, so my link is '#gallery'. In …
Category: Web

Wordpress add page under admin submenu and retaining the active status of the parent submenu page in the menu

I have added a page in the admin menu(pxmag-menu) and a submenu(pxmag-plans). There is another page(pxmag-plans-edit) set under the submenu(pxmag-plans) as the parent page. public function __construct() { require('pxMagAdminPlans.class.php'); $this->admPlanObj= new pxMagAdminPlans(); add_action('admin_menu', array($this, 'add_plan_admin_menu')); } public function add_plan_admin_menu() { add_menu_page(__('Dashboard', 'textdomain'), get_bloginfo('name'), 'manage_options', 'pxmag-menu', array($this, 'pxmag_dash'), 'dashicons-welcome-view-site', 6); add_submenu_page('pxmag-menu', __('Subscription Plans', 'textdomain'), 'Plans', 'manage_options', 'pxmag-plans', array($this->admPlanObj, 'plan_admin_menu_page')); add_submenu_page('pxmag-plans', __('Add/edit Plans', 'textdomain'), 'Add/edit plans', 'manage_options', 'pxmag-plans-edit', array($this->admPlanObj, 'plan_admin_menu_edit')); } All the menu and submenu pages load fine. But, when I …
Category: Web

Set different custom menu items for different user roles

I have added some custom menu using add-menu_page and it is working perfectly with the default administrator admin bar. But when I log in to different user roles, they are not showing. My question is how to show different menu items for different users. I have added these codes to my plugin main function.php file function custom_admin_menu() { global $menu, $submenu; $icon = get_option('cqpim_use_default_icon'); if(empty($icon)) { $adicon = PTO_PLUGIN_URL . '/img/icon.png'; } else { $adicon = ''; } // My …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.