Saturday, October 15, 2011

How to add menu to admin side bar

In this tutorial i will show you how to add a menu item in admin menu.Wordpress has made the process very simple we just have to call few hooks and write few lines of code.The code for this will also be stored in wordpress plugin directory.

How to do it?
1-Make a folder in wordpress -> wp-content -> plugins
2-Make a php file and put the file inside it.
3-Then go to admin panel and look at the link it would be there.



In our example we will have a folder called admin-menu and php file admin-menu.php.

Code for adim-menu.php
< ?php
/*
Plugin Name: Admin Menu
Plugin URI: http://wp-help.blogspot.com/
Description: Admin Menu
Author: zalmai khan
Author URI: http://wp-help.blogspot.com/
*/

// Hook for adding admin menus
add_action('admin_menu', 'mt_add_pages');

// action function for above hook
function mt_add_pages() {

// Add a new top-level menu (ill-advised):
add_menu_page(__('Your Menu Title'), __('Your Menu name'), 'manage_options', 'mt-top-level-handle', 'mt_toplevel_page' );

}

// mt_toplevel_page() displays the page content for the custom Test Toplevel menu
function mt_toplevel_page() {
echo "

" . __( 'page contents for the menu' ) . "

";
}

?>

Friday, October 14, 2011

Hello word plugin wordpress

How to write plugins in word press?
Writing plugins in wordpress is not difficult.I will show you how to write simple plugin in wordpress and we will start with hello word plugin The hello word wordpress plugin illustrate the file structure and the position of wordpress plugins.For every language the hello word program best describe the process of writing the code.




Hello-word.php file code :

< ?
/*
Plugin Name: Hello-World
Plugin URI: http://wp-help.blogspot.com/
Description: A simple hello world wordpress plugin
Version: 1.0
Author: Balakrishnan
Author URI: http://wp-help.blogspot.com/
License: GPL
*/
/* This calls hello_world() function when wordpress initializes.*/

add_action('init','hello_world');
function hello_world()
{
echo "Hello World";
}
?>

Save this file in wordpress > wp-contents>plugins>hello-word.Then go to admin and click on plugins and you will see the plugin hello word there.