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_printas callback ofadmin_noticesor ofadd_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_pagecannot 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: