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

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 );
}

Related

Directing to filtered pages from Wordpress Admin Sub Menus

I want to add two additional sub-menu items to my Wordpress Admin menu. The top-level menu I want to hook into is the 'Products' menu created by WooCommerce.
edit.php?post_type=product
The content I want the menu items to show can be accessed by filtering the products by Product Category. E.g.
http://dev3.benefacto.org/wp-admin/edit.php?s&post_type=product&product_cat=manchester
I've come up with a working solution (below) to do this - but it is inelegant because it requires calling a function when I feel like I should be able to simply add something into the 'menu slug' variable perhaps.
Any thoughts much appreciated.
// Hook into the Admin Menu
add_action( 'admin_menu', 'lnz_wp_adminmenu_addproductpages' );
// Add Product Categories
function lnz_wp_adminmenu_addproductpages() {
add_submenu_page( 'edit.php?post_type=product', 'Manchester Charities - Page', 'Manchester Charities- Menu', 'manage_options', 'product_cat_manchester', 'lnz_wp_adminmenu_redirectmanchester' );
add_submenu_page( 'edit.php?post_type=product', 'London Charities - Page', 'London Charities- Menu', 'manage_options', 'product_cat_london', 'lnz_wp_adminmenu_redirectlondon' );
}
// Create Redirects for relevant links
function lnz_wp_adminmenu_redirectmanchester() {
header('Location: http://dev3.benefacto.org/wp-admin/edit.php?s&post_type=product&product_cat=manchester');
exit();
}
function lnz_wp_adminmenu_redirectlondon() {
header('Location: http://dev3.benefacto.org/wp-admin/edit.php?s&post_type=product&product_cat=london');
exit();
}
As far as I know, there's no direct way to achieve this using WP hooks or modifying something like global $submenu...
It can be done with jQuery modifying the href attribute of the submenu items:
add_action( 'admin_menu', function() {
add_submenu_page( 'edit.php?post_type=product', 'Manchester', 'Manchester', 'manage_options', 'cat_manchester', '__return_null' );
add_submenu_page( 'edit.php?post_type=product', 'London', 'London', 'manage_options', 'cat_london', '__return_null' );
});
add_action('admin_footer', function(){
?>
<script>
jQuery(document).ready( function($) {
var admin_url = 'http://dev3.benefacto.org/wp-admin/edit.php';
$('#menu-posts-product').find('a[href*="cat_manchester"]').attr('href',admin_url+'?s&post_type=product&product_cat=manchester');
$('#menu-posts-product').find('a[href*="cat_london"]').attr('href',admin_url+'?s&post_type=product&product_cat=london');
});
</script>
<?php
});

Wordpress Issue Create Sub Menu

I just making sure that I'm creating the submenu on dashboard correctly.
I'm watching a tutorial on how to create a Setting API on Youtube
The problem is when every I hover on ALLB Option Sitting does pop up with the submenu.
Can anyone help with this quick issue having on WordPress, please explain with detail?
<?php
/*
====================
Admin Page
====================
*/
function allb_admin_page() {
//Generate A Legacy Left Behind Admin Page
add_menu_page( ' ALLB Theme Options', 'ALLB Options', 'manage_options', 'a_legacy_left_behind', 'allb_theme_create_page', 'dashicons-admin-customizer', 110);
//Generate A Legacy Left Behind Admin Sub Page
add_submenu_page('allb_theme', 'ALLB Theme Options', 'Setting', 'manage_options', 'a_legacy_left_behind', 'allb_theme_settings_page');
}
add_action('admin_menu', 'allb_admin_page');
function allb_theme_create_page() {
// genration of our admin page
}
function allb_theme_settings_page() {
// genration of our admin page
}
Here is the answer..
Just copy and past this code in your theme's functions.php file..
Would you please try it once ?
add_action('admin_menu', 'my_menu_pages');
function my_menu_pages(){
add_menu_page('My Page Title', 'My Menu Title', 'manage_options', 'my-menu', 'my_menu_output' );
add_submenu_page('my-menu', 'Submenu Page Title', 'Whatever You Want', 'manage_options', 'my-menu' );
add_submenu_page('my-menu', 'Submenu Page Title2', 'Whatever You Want2', 'manage_options', 'my-menu2' );
}
I hope its helpful for you..
Hope this will solve your issue
function allb_admin_page() {
//Generate A Legacy Left Behind Admin Page
add_menu_page( 'ALLB Theme Options', 'ALLB Options', 'manage_options', 'a_legacy_left_behind', 'allb_theme_create_page');
//Generate A Legacy Left Behind Admin Sub Page
add_submenu_page('a_legacy_left_behind', 'ALLB Theme Options', 'Setting', 'manage_options', 'a_legacy_left_behind_sub', 'allb_theme_settings_page');
}

Add menu page is creating submenu with same title name

I am using this function to create menu option in wp dashboard
add_menu_page(
__('Advertisement Pages'),// the page title
__('Advertisement'),//menu title
'edit_themes',//capability
'a-advertise',//menu slug/handle this is what you need!!!
'display_all_ad',//callback function
'',//icon_url,
'15'//position
);
it is creating menu the name of Advertisement but also creating submenu with the same name.
try this
add_action( 'admin_menu', 'advertisement_menus' );
function advertisement_menus() {
add_menu_page( 'Advertisement Pages', 'Advertisement', 'edit_themes', 'advertisement_slug', 'display_all_ad', '', 15 );
}
//and your call back function
function display_all_ad(){
echo "this is call back";
}

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