How to add menu item on dashboard menu in wordpress - wordpress

I am trying the following syntax to add the custom menu on dashboard. and I put this code in 'function.php' in theme folder file. but its not displaying menu on dashboard. So, please help me in which file I put this code? otherwise any other solution please help me.
<?php
add_action( 'admin_menu', 'register_my_custom_menu_page' );
function register_my_custom_menu_page(){
add_menu_page( 'custom menu title', 'custom menu', 'manage_options', 'custompage', 'my_custom_menu_page', plugins_url( 'myplugin/images/icon.png' ), 6 );
}
function my_custom_menu_page(){
echo "Admin Page Test";
}
?>

In which function.php file are you writing this code? are you writing in the core files? if you are writing in the theme's function file just make sure that the theme is currently active.

Related

Feature image option won't show in portfolio

I am making a wordpress theme
But the problem is i can not enable feature image option in Portfolio
I have added the following code in the function.php
add_theme_support( "post-thumbnails", array('portfolio', 'post'));
This code is working for posts but not for portfolio
is it because of any of these plugins that i am using
Advanced Custom Fields
Custom Post Type UI
Akismet
enter image description here
try this in fucntion.php file
function custom_theme_setup() {
add_theme_support( 'post-thumbnails', array('post', 'page', 'popup') );
}
add_action( 'after_setup_theme', 'custom_theme_setup');

How do I assign wordpress plugin to menu?

wp-content/plugins/myplugin.php
how to assign this plugin to top level menu? E.g. menu on my website: about us contacts, services my plugin. I'm using add_menu_page but I dont know why its not working.
I have used it, when prepare my theme. You may used it also. Put it at functions.php
add_action( 'admin_menu', 'register_YOURPLUGINNAME_menu_page' );
function register_YOURPLUGINNAME_menu_page(){
add_menu_page( 'PLUGIN Info', 'PLUGINNAME', 'manage_options', 'custompage', 'YOURPLUGIN_menu_page', 'dashicons-tickets' , 10 );
}
function YOURPLUGIN_menu_page(){
?>
<h1>TEST YOUR MIGHT :)
<?php
}
?>

Create a top level menu in wordpress admin for a child theme

I am creating a dedicated theme for an app with some custom settings that will be used just a few times to set up the app from a fresh wordpress install.
How do I create a top level menu in wordpress admin for a twenty twelve child theme via functions.php and a page to contain the settings? I would like to have it as the first item in the menu.
Here's a solution. Just put this code in the functions.php
<?php
/******* New menu item for admin *********/
add_action( 'admin_menu', 'register_my_custom_menu_page' );
function register_my_custom_menu_page(){
add_menu_page( 'custom menu title', '♥Custom theme options♥', 'manage_options', 'custompage', 'my_custom_menu_page', '' /* or something like ... plugins_url( 'myplugin/images/icon.png' )*/, 1 );
}
function my_custom_menu_page(){
?>
Hello world. This is a simple example page.
<?php
}
?>

How to display page title of menu / sub menu page?

I would like to know what the usage of $page_title in function add_menu_page or add_submenu_page because I don't see it in the menu / sub menu page.
To have the title, I have to manually code the plugin, such as :
<div class="wrap">
<h2>Page Title</h2>
....
Here is the code for creating menu / sub menu :
add_menu_page(
'Menu Page Title',
'Menu Title',
'publish_posts',
'otto-ext' );
add_submenu_page(
'otto-ext',
'Sub Menu Page Title',
'Sub Menu Title',
'publish_posts',
'location-ext',
'custom_menu' );
Is it possible to display "Menu Page Title" or "Sub Menu Page Title" automatically?
Thanks in advance
I know I'm two years late to the party, but for those still landing on this page:
You can use get_admin_page_title(), which has been available since 2.5. Alternatively, you can just use $GLOBALS['title'], which WordPress sets as soon as admin-header.php is loaded.
<div class="wrap">
<h2><?php echo $GLOBALS['title'] ?></h2>
<!-- ... -->
</div>
You are correct. You will have to code the title manually. The $page_title parameter is only for the title tag in the head section of the HTML document, <title>$page_title</title>, which is used as the "name" of the tab in your browser.
There is no way to use the parameters given to add_menu_page inside the function that echoes the content of the page you're creating. So no, there is no easy way to generate page titles automatically from that information.
Here is an example of a menu and sub-menu using scripts:
add_action( 'admin_menu', 'MyPluginMenu' );
function MyPluginMenu() {
$SettingsPath = 'path_to_plugin/menu_script.php';
add_menu_page( 'PageTitle', 'MenuTitle', 'administrator', $SettingsPath, '', plugins_url( 'path_to_plugin/images/plugin_icon.png' ) );
add_submenu_page( $SettingsPath, 'PageTitle', 'SubMenuTitle', 'administrator', 'path_to_plugin/sub_menu_script.php', '' );
}
This will work for PLUGINS as you mentioned in your question I have to manually code the plugin, such as:.

My wordpress plugin wont be added to the left-side menu

I have built a very simple plugin and uploaded it on my wordpress account which is run on localhost. Once I activate it, its output will be shown on every page, and it wont be added to the left hand side menu of wordpress. what should I add to it to be added to the menu? I suppose it should be done using add_action but do not know how !!
<?php
/*
Plugin Name: myphotos Plugin
Description: A simple wordpress plugin.
Version: 1.0
Author: Saeed Pirdost
Copyright: 2012, Saeed Pirdost
*/
?>
<?php
add_filter('admin_notices','myprint');
?>
function myprint()
{
echo "hello";
}
?>
I used the following code as well but when I activate the plugin just a white page will be shown.
add_menu_page(__('My Menu Page'), __('My Menu'), 'edit_themes', 'my_new_menu', 'myprint', '', 7);
First, stop opening and closing PHP tags at every line, you don't need that. This is used when some HTML is happening in the middle of your PHP.
Also, the last closing ?> of a PHP file can/should be omitted. It may even break a site if there is a white-space after it...
Refer to WordPress_Coding_Standards.
Second, you need to decide if you want to use the function my_print as callback of admin_notices or of add_menu_page. Can it be both? In this case, yes, but really, do it only if you know what you are doing.
Your plugin is breaking because add_menu_page cannot be called directly.
Always check the documentation of each function that don't work as expected:
Function_Reference/add_menu_page
Here's a working version of your plugin:
<?php
/*
Plugin Name: myphotos Plugin
Description: A simple wordpress plugin.
Version: 1.0
Author: Saeed Pirdost
Copyright: 2012, Saeed Pirdost
*/
add_filter( 'admin_notices', 'print_my_notice' );
add_action( 'admin_menu', 'register_custom_menu_page' );
function print_my_notice()
{
echo '<div class="updated">
<p>I am a big notice that appears everywhere</p>
</div>';
}
function register_custom_menu_page()
{
add_menu_page(
__( 'My Menu Page', 'my-plugin-text-domain' ),
__( 'My Menu', 'my-plugin-text-domain' ),
'edit_themes',
'my_new_menu',
'print_my_menu',
'http://upload.wikimedia.org/wikipedia/commons/a/aa/Wink%2816px%29.svg',
7
);
}
function print_my_menu()
{
echo '<div id="icon-post" class="icon32"></div>
<h2>My plugin</h2>
<p><a class="button-secondary" href="#"> '
. __( 'I am a translation', 'my-plugin-text-domain' )
. '</a>
</p>';
}
Open your wordpress Admin Area
Click on appearance->widgets
Drag and drop the Menu to desired place
Or
Click Appearance -> Menu
and click on sidebar menu
and add items there
Hope it helps

Resources