Wordpress submenu is blank - php

I've been willing to add a submenu to an existing plugin (school project), except that i can see it in the menu, but anytime i open it the page is empty.
Anyone know why it might does this?
static function admin_menu() {
add_menu_page(
_x( 'Foyer', 'plugin name in admin menu', 'foyer' ),
_x( 'Foyer', 'plugin name in admin menu', 'foyer' ),
'edit_posts',
'foyer',
array(),
'dashicons-welcome-view-site',
31
);
add_submenu_page(
'tools.php',
'Foyer Settings', //page title
'Settings', //menu title
'edit_plugins', //capability,
'foyer-settings',//menu slug
'my_custom_submenu_page_content'//callback function
);
}
function my_custom_submenu_page_content() {
echo '<div class="wrap">';
echo '<h2>Page Title</h2>';
echo '</div>';
}

Related

Add custom link as a sub menu, below WooCommerce in Admin Area

I'm trying to add a custom link as a submenu, below WooCommerce, under "Orders".
I've tried using the following code, but I'm missing something. How do I add a custom link?
add_action('admin_menu', 'register_my_custom_submenu_page');
function register_my_custom_submenu_page() {
add_submenu_page( 'woocommerce', 'My Custom Submenu Page', 'My Custom Submenu Page',
'manage_options', 'my-custom-submenu-page', 'my_custom_submenu_page_callback' );
}
function my_custom_submenu_page_callback() {
echo '<h3>My Custom Submenu Page</h3>';
}
I used the following code to add a custom link, under WooCommerce:
// Adding custom sub menu
add_action('admin_menu', 'add_custom_link_into_appearnace_menu');
function add_custom_link_into_appearnace_menu() {
global $submenu;
$permalink = 'http://www.cusomtlink.com';
$submenu['woocommerce'][] = array( 'POS Orders', 'manage_options', $permalink );
}

Add submenu entry to WooCommerce "Products" admin menu

I would like to add a submenu entry under the WooCommerce "Products" admin menu. Does anybody know what the $parent_slug for this menu is?
I can add a submenu item to the "WooCommerce" menu using add_submenu_page and 'woocommerce' for $parent_slug (via the admin_menu hook), but can't seem to figure out what the $parent_slug for the Products menu is...
if ( is_admin() ) {
add_action( 'admin_menu', 'add_products_menu_entry', 100 );
}
function add_products_menu_entry() {
add_submenu_page(
'woocommerce-product', // This is what I can't figure out
__( 'Product Grabber' ),
__( 'Grab New' ),
'manage_woocommerce', // Required user capability
'ddg-product',
'generate_grab_product_page'
);
}
function generate_grab_product_page() {
// Page generation code will go here
}
WooCommerce Products Admin Menu
Got it, it was edit.php?post_type=product
if ( is_admin() ) {
add_action( 'admin_menu', 'add_products_menu_entry', 100 );
}
function add_products_menu_entry() {
add_submenu_page(
'edit.php?post_type=product',
__( 'Product Grabber' ),
__( 'Grab New' ),
'manage_woocommerce', // Required user capability
'ddg-product',
'generate_grab_product_page'
);
}
function generate_grab_product_page() {
echo "<h2>Hello, it worked! :-)</h2>";
}
Thank-you to Derick Rethans / XDebug!

Adding the custom page with add_menu_page function on Wordpress

I am using the add_menu_page function on WordPress; this is the code;
function my_admin_menu() {
add_menu_page( 'My Top Level Menu Example', 'Top Level Menu',
'manage_options', 'example.php', 'myplguin_admin_page', 'dashicons-tickets', 6 );
}
example.php
function display_text() {
echo 'Welcome to my page';
}
I get the menu in the dashboard, but the issue has content on the page. I can click the top-level option page from the dashboard, but once I do that, I get an empty page where it should say 'Welcome To My page'. Any ideas on how to get my content to show?
You were using a wrong function name that is why it was showing a blank page.
function my_admin_menu() {
add_menu_page( 'My Top Level Menu Example', 'Top Level Menu', 'manage_options', 'example.php', 'myplguin_admin_page', 'dashicons-tickets', 6 );
}
function myplguin_admin_page(){
echo 'Welcome to admin page';
}
You can try this code, because i use this and work
add_menu_page(
'Import Resi', // Page Title
'Import Resi', // Menu Title
'manage_options', // Capabiliy
'import_php/index.php', // Menu_slug
'', // function
'', // icon_url
6 // position
);
add_menu_page(
'Admin Cek', // Page Title
'Admin Cek', // Menu Title
'manage_options', // Capabiliy
'admin_cek/index.php', // Menu_slug
'', // function
'', // icon_url
7 // position
);
you need to use the correct function name and a more appropriate identifier than example.php. you can require your file from the called function
function my_admin_menu() {
add_menu_page( 'My Top Level Menu Example', 'Top Level Menu', 'manage_options', 'example', 'display_text', 'need a uri to your image here!!', 6 );
}
function display_text(){
require_once 'pathtofile.php'; //--> make sure you read up on paths and require to find your file.
}

Change location of custom settings page in wordpress backend

How can i adapt the following code to show my custom “Theme Settings” page under “appearence” and NOT under “settings” in the wordpress backend?
add_action('admin_menu', 'theme_options_page'); function theme_options_page() { add_options_page('Theme Settings', 'Theme Settings', 'administrator', __FILE__, 'build_options_page');
Here you can find the full code snippet
using add_submenu_page
add_submenu_page( themes.php, 'Title of Page', 'Theme Options', 'manage_options', 'custom_options', 'custom_function' );
function custom_function()
{
// add your form code here or include a file here
}
for under Appearance use themes.php as parent_slug
or you can also use
using add_theme_page
add_theme_page( 'this is page Title', 'Theme Options', 'manage_options', 'custom_options', 'custom_function' );
for more info please check
you can check

Creating Custom Options page in wordpress and adding sub_menu_page

Below is my code, the code generates a user custom options menu page, after adding the sub menu page, when I click the sub menu option, the page refreshes but the sub menu page content is not visible, only the main page content sticks. Please help me to where I am wrong. Do I have to register_setting or any thing else....
<?php
// create custom plugin settings menu
add_action('admin_menu', 'omr_create_menu');
add_action('admin_menu', 'omr_create_submenu');
function omr_create_menu() {
//create new top-level menu
add_menu_page('My Menu Page', 'Main Menu', 'administrator', __FILE__, 'main_menu_page', 'favicon.ico');
}
?>
<?php
function main_menu_page() {
global $title;
?>
<h2><?php echo $title;?></h2>
My New Menu Page!!
<?php
}
function omr_create_submenu(){
add_submenu_page(__FILE__, 'My SubMenu Page', 'My Submenu', 'administrator', 'my_new_submenu', 'my_submenu_page');
}
function my_submenu_page() {
global $title;
?>
<h2><?php echo $title;?></h2>
My New Submenu Page!!
<?php
}
?>
I think you are using the same content page for both menu and submenu with _file_, so you don't see the sbu muen page.
works both:
add_menu_page('My Menu Page', 'Main Menu', 'administrator', __FILE__,
'main_menu_page', 'favicon.ico');
add_submenu_page(__FILE__, 'My SubMenu Page', 'My Submenu', 'administrator',
'my_new_submenu', 'my_submenu_page');
and
add_menu_page('My Menu Page', 'Main Menu', 'administrator', 8, 'main_menu_page',
'favicon.ico');
add_submenu_page(8, 'My SubMenu Page', 'My Submenu', 'administrator', 1,
'my_submenu_page');

Categories