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";
}
Related
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 );
}
Can you please help me with my proble regarding creating a New Page for Editing Details.
Currently, I have a list of Properties. This is a Custom Table not a post type. I already listed the properties but my problem is how am I gonna make the Edit Details Page?
add_action( 'admin_menu', 'pp_create_property_management_menu' ); function pp_create_property_management_menu() {
add_menu_page( 'PP M', 'PP M', 'manage_options', 'property-management', 'pp_property_management_page', 'dashicons-tickets', 5 ); }
Many thanks,
The fifth parameter in the add_menu_page() function calls a function to output the contents of the menu page. Here's an example I have taken from the WordPress site on how to add a custom admin menu and show the details of the page.
add_action( 'admin_menu', 'my_plugin_menu' );
function my_plugin_menu() {
add_menu_page( 'My Page Title', 'My Menu Title', 'manage_options', 'my-unique-identifier', 'my_plugin_options' );
}
function my_plugin_options() {
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
echo '<div class="wrap">';
echo '<p>Put all your options in here</p>';
echo '</div>';
}
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
});
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.
}
I'm creating a new plug for my project I have the like in the admin menu and i have created the landing page I would like to know how i can create a new page within my plugin.
So if I was to click on View All Images how could i navigate to a new page within my plugin?
add_action('admin_menu', 'test_plugin_setup_menu');
add_action('admin_enqueue_scripts', 'my_admin_scripts');
function test_plugin_setup_menu(){
add_menu_page( 'Test Plugin Page', 'Test Plugin', 'manage_options', 'test-plugin', 'test_init' );
}
function test_init(){
echo "<a href='#'>View All Images</a>";
}
Use plugins_url() function
function test_init(){
echo "<a href='<?=plugins_url();?>/your_file.php'>View All Images</a>";
}