How can I create a new menu item that links to an archive of a custom post type?

After searching through the core WordPress files, I found the necessary arguments. The key is setting menu-item-object to be the slug of your post type and the menu-item-type to be post_type_archive. $args = [ ‘menu-item-position’ => $position, ‘menu-item-status’ => ‘publish’, ‘menu-item-parent-id’ => 0, ‘menu-item-object’ => ‘my-post-type’, ‘menu-item-type’ => ‘post_type_archive’ ]; wp_update_nav_menu_item($menuID, 0, $args);

add page to main menu (frontend)

In order to know what are locations provided by theme for menus: $locations = get_nav_menu_locations(); This command will return an associative array that has for keys the locations and for values the ids of menu assigned to that location. To know what pages are associated to a menu: $idmenu = $locations[‘main-menu’]; $menu = wp_get_nav_menu_object( $idmenu … Read more

Plugin add_action and add_menu_page

The main difference is the location where the style (link) or script tag be in the source, or whether the resource is loaded in head or the footer. With a add_menu_page()/add_submenu_page() callback like your foo_settings_page(), the style/script file would be loaded in the body (before the closing body tag), because the head has already been … Read more

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

If I understand it correctly — you want the “Plans” sub-menu to be highlighted when on the “Add/edit plans” (pxmag-plans-edit) page, then you can do it like so: Use the add_menu_classes hook to highlight the pxmag-menu menu: function my_add_menu_classes( $menu ) { // Do nothing if not on the “Add/edit plans” page. global $plugin_page; if … Read more

Add menu item to edit specific page

You’ve almost answered your own question. Just pass the URL as the $menu_slug to add_menu_page: add_menu_page( null, // not an actual page, so title is irrelevant ‘Menu Item Name’, ‘edit_posts’, // or whatever capability required for this object ‘/post.php?post=42&action=edit’, null, ”, 6 ); The caveat is that when you visit this menu item, the actual … Read more

meta box on new admin page

You are trying to create a new admin page with add_pages_page(). Meta boxes are only for existing post types, not for admin pages. You need to create your fields like on a normal admin page. You should read the official codex about this first: Creating Options Pages For a simple start take a look at … Read more

WordPress custom plugin gives error

It seems that your function wstock_variation not exists or is created in PHP file not include in your plugin… If you are using OOP, for example your code need to be like: add_submenu_page( ‘Elites-StockManager’, ‘Smart Stock Manager’, ‘export’, ‘administrator’, ‘wstock_variation’, array($this, ‘wstock_variation’) ); // remove number 8, method accept only 6 params $this is method … Read more

Finding the screen id of a page generated with add_menu_page

The function add_menu_page return the hook suffix that inform you about the current page. A simple example to get the hook suffix. public function add_menu_page() { $page_hook_suffix = add_menu_page( esc_html__( ‘Admin Page’, ‘translation-slug’ ), esc_html__( ‘Admin Page’, ‘translation-slug’ ), ‘read’, ‘My Name’, array( $this, ‘get_styles’ ) ); add_action( ‘admin_print_scripts-‘ . $page_hook_suffix, array( $this, ‘enqueue_assets’ ) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)