8 Easy Steps of how to create a Custom Post type Plugin in WordPress
This post will provide you a very easiest way to create the custom post type plugin in WordPress which automatically creates your plugin with the default functionality that a WordPress plugin will have.Plugin folder Structure:
- wp-content
- places_to_visit(folder-name)
- index.php
- css
- style.css
- js
- jquery.js
- images
- logo.png
Follow this Steps and you will find it Interesting of how easy the plugin creation is in WordPress.
Step:1 Create a New Folder inside the Plugins folder which you find it inside the wp-content.
Step:2 Name the New folder which you have created with the custom post-type plugins name that you are going to create.
Step:3 Open up your editor with a new file which you are using and paste the below code in that and save the file name as "index.php"
Index File Code:
<?php
/*
Plugin Name: Places to Visit
Plugin URI: http://nareshkumar979.blogspot.in/
Description: The plugin helps the tourists to know what are all the places available to visit when then plan to spend a vacation at a particular place.
Version: 1.0
Author: Naresh Kumar.P
Author URI: http://nareshkumar979.blogspot.in/
License: NK001
*/
//Starting of the Custom Post Type called "Places to Visit"
add_action( 'init', 'places_to_visit' );
function places_to_visit()
{
$args = array(
'labels' => array(
'name' => 'Places to Visit',
'singular_name' => 'Place to Visit',
'add_new' => 'Add New',
'add_new_item' => 'Add New Places to Visit',
'edit' => 'Edit',
'edit_item' => 'Edit Places to Visit',
'new_item' => 'New Places to Visit',
'view' => 'View',
'view_item' => 'View Places to Visit',
'search_items' => 'Search Places to Visit',
'not_found' => 'No Places to Visit found',
'not_found_in_trash' => 'No Places to Visit found in Trash',
),
'menu_position' => 15,
'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields' ),
'menu_icon' => plugins_url( 'images/logo.png', __FILE__ ),
'public' => true
);
register_post_type( 'places_to_visit',$args);
}
//End of the Custom Post Type called "Places to Visit"
?>
Points to Ponder:
Note: The plugin Index file should not contain any spaces between the codes. It should be coded as per my "index.php" file.
"If index.php file is coded with spaces it will create warning dialog at the time of plugin activation"
In this plugin the post type will be "places_to_visit".
"supports"-> This will decide what are all functionalities and input fields that your plugin can have.
(eg.) I have added
- title: will hold the Post Name
- editor: used for entering the contents for that particular posts.
- thumbnail: used for having a image for the post.
- custom-fields: It will be displayed if you create the custom fields for the posts that you create(Will explain in the Later posts of how to create custom fields for the particular posts)
Step:4 Create a folder called "images" inside the custom post-type folder and place the image which you want to keep as icon for you plugin.
Note: the icon size should be either (24X24 or 32X32). Other than this size the icon will not fit in the menu place.
Step:5 For adding the css and js create seperate folder as you done for the images and include it in the pages which you need.
Step:6 At last after doing all this you go to the WordPress dashboard by logging in and move to the Plugins Menu.
Step:7 You will find the Name of the Plugin which you have created under the "Activate" mode.
Step:8 If you click on Activate your plugin will be activated and you will find your plugin in Sidebar Menu.
No comments:
Post a Comment