WordPress menu add link to plugins - wordpress

When the admin is logged in and is in front end area, there is a small dropdown of the quick menus. How can I add link to plugins page here?

function my_tweaked_admin_bar() {
global $wp_admin_bar;
$wp_admin_bar->add_menu( array(
'id' => 'plugins',
'title' => 'Plugins',
'href' => get_site_url().'/wp-admin/plugins.php',
'parent'=> 'site-name'
));
}
add_action( 'wp_before_admin_bar_render', 'my_tweaked_admin_bar' );
Just paste this code in functions.php in your current theme's directory.
For more information check WordPress Codex:
https://codex.wordpress.org/Plugin_API/Action_Reference/wp_before_admin_bar_render

Related

Add a secondary menu to my wordpress website

I am trying to add a secondary menu to my Wordpress website. My goal is to display it at the very top of my website (https://cadinwebsite.wpcomstaging.com/), above the logo.
I have installed code snippets plugin and inserted the following code:
function wpb_custom_new_menu() {
register_nav_menu('my-custom-menu',__( 'My Custom Menu' ));
}
add_action( 'init', 'wpb_custom_new_menu' );
The code above works correctly and creates a new menu location in my "menus" dashboard.
But then, when I add the code below to display the newly created menu, my website crashes.
<?php
wp_nav_menu( array(
'theme_location' => 'my-custom-menu',
'container_class' => 'custom-menu-class' ) );
?>
I also tried to input the second part of my code in the header section, but it doesn't work either. What I am doing wrong?
We have checked and you made mistake in your add action code, please check with below code, and try with that
add_action( 'after_setup_theme', 'register_my_menu' );
function register_my_menu() {
register_nav_menu( 'my-custom-menu', __( 'My Custom Menu', 'theme-text-domain' ) );
}
wp_nav_menu( array(
'theme_location' => 'my-custom-menu',
'container_class' => 'custom-menu-class'
) );

Placing Wordpress plugin name at the top of the amdin header

I have a Wordpress plugin which I've named 'Solve Maths'. I want this plugin name to be displayed only at the Admin header of the Arthur alone for easy access.
I used the admin_head action hook but once I installed the plugin, the system tells me my plugin has generated these number of characters at the header.
<?php function Solve_Maths{ echo "<a href='Solve_Maths.php'>Solve Maths</a>";} add_action('admin_head','Solve_Maths');?>
The Solve_Maths.php is the name of the main plugin file with the header information. I want this file name in the tag to be shown at the admin header of the user and should execute the file when the link is linked. Thank you all for your help.
This is not the correct way to do it. Please check the WordPress Codex and refer to the function add_node: https://codex.wordpress.org/Function_Reference/add_node
add_action( 'admin_bar_menu', 'toolbar_link_to_mypage', 999 );
function toolbar_link_to_mypage( $wp_admin_bar ) {
$args = array(
'id' => 'my_page',
'title' => 'My Page',
'href' => 'http://example.com/my-page/',
'meta' => array( 'class' => 'my-toolbar-page' )
);
$wp_admin_bar->add_node( $args );
}

Unable to get wordpress register_nav_menus working

I am building my 1st theme, and got stucked with showing menu option on admin's screen under appearance. I refered various support thread but none of the solution is working for me.
Codes in function.php
<?php
//Create Nav menu
if (function_exists(register_nav_menus)) {
register_nav_menus( array('primary' => 'Header Navigation') );
}
?>
Codes in header.php
<?php
wp_nav_menu( array( 'container_class' => 'main-nav' , 'container'=>'nav') );
?>
I am executing this on localserver and wordpress version 4.0
image of header.php
http://i.imgur.com/ziPGH2G.png
image of function.php
http://i.imgur.com/ica5VJx.png
Thats all of it.
Please help me out.
First rename function.php to functions.php , note the the "s". http://codex.wordpress.org/Functions_File_Explained
Second try registering the menu inside a hook like init or after_theme_setup
add_action( 'after_setup_theme', 'register_my_menu' );
function register_my_menu() {
register_nav_menu( 'primary', 'Header Navigation' );
}
You're missing some arguments (and a comma in your array). You need to pass in a menu name:
$args = array(
'menu' => 'primary',
'container' => 'nav',
'container_class' => 'main-nav',
);
wp_nav_menu( $args );
Also be aware that this menu must exist in the admin, and must be assigned to the menu location you just created.

wordpress, custom menu is created but does not show up in the top head part in the admin panel

My theme has several custom menus. I can manage them in the WP admin panel.
But look at the picture. You see 2 menus already created - Footer Menu and Header. But in my case those 2 names do not appear so I cannot do anything with them later.
Code I used:
add_action( 'init', 'menus_all' );
function menus_all() { register_nav_menus( array(
'menu1' => _( 'menu1 loc'),
'menu2' => _( 'menu2 loc'),
) ); }
How to make the menu names appear ?
register_nav_menu goes straight in your functions.php file, without any hook:
register_nav_menus( array(
'menu1' => _( 'menu1 loc'),
'menu2' => _( 'menu2 loc'),
));

add menu item to the dashboard menu of wordpress

I am trying the following syntax to add menu-item on dashboard:
<?php add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); ?>
But, I am confused where to add this code.
Whether to add it in my theme's functions.php or my plugin's functions.php ?
Or any other way to add custom menu-item on the dashboard of the wordpress logged in as admin ?
I want to add custom menu item like the following image:
What you see in the screenshot is the screen of a Custom Post Type. In the documentation you will find an example code on how to add such a screen.
About where to place the code - it depends. Do you want to be able to use this Custom Post Type in other themes, or you will only need it in this theme?
If you want to use it in other themes as well, put the code in your plugin's code.
If you want to use it only in this theme, put it in your theme's functions.php.
And in case you still want to add a custom menu page, here you will find examples on what is the proper way to use this function. What you should note, is that the call to add_menu_page() should be done inside a function that is run on the admin_menu action.
Here's an example working code with WP 3.4.2
function register_custom_menu_page() {
add_menu_page('custom menu title', 'custom menu', 'add_users', 'custompage', '_custom_menu_page', null, 6);
}
add_action('admin_menu', 'register_custom_menu_page');
function _custom_menu_page(){
echo "Admin Page Test";
}
This is a perfect answer.
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'acme_product',
array(
'labels' => array(
'name' => __( 'Products' ),
'singular_name' => __( 'Product' )
),
'public' => true,
'has_archive' => true,
)
);
}

Resources