How to Create Custom Plugins in WordPress

A theme can also change a site's functionality, while a plugin can make alterations to its appearance. If there’s one cardinal rule in WordPress development, it’s this: Don’t touch WordPress core. This means that you don’t edit core WordPress files to add functionality to your site.

This is because, when it updates to a new version, it overwrites all the core files. Any functionality you want to add should therefore be added through plugins using approved WordPress APIs. If you have a great idea for a plugin but need some help creating it, try the below code. Easily we Create WP Custom Plugins.

Below are the steps to create a custom plugin in WordPress:

  • Create a new folder for Your plugin: Create Folder in Wp-content/plugins/New Folder (contact-details)
  • Create the main PHP file for Your plugin (contact-details.php)
  • Setup Your plugin's information: Open the file in a text editor, and paste the following information in it:

<?php
/*
Plugin Name: Contact Details
Description: A test plugin to demonstrate WordPress functionality
Author: Sumita Dey
Version: 0.1
*/
add_action('admin_menu', 'contact_details_setup_menu');
function contact_details_setup_menu(){   
        add_menu_page( 'Contact Details Page', 'Contact Details', 'manage_options', 'contact_details', 'contact_details_init' );		
}
function contact_details_init(){
/*get  results form table*/
global $wpdb;
   if(isset($_POST)){
   $table = wp_form_creating;
$row_id=array( 'id' => $_POST['id'] );
$success=$wpdb->update( $table, $_POST,$row_id);
}
$customers = $wpdb->get_results("SELECT * FROM wp_contact_form;");
echo '<div id="status_msg"></div><table class="profile-table table-bordered">
<tr>
 <th>Name</th>
<th>E-mail</th>
<th>Subject</th>
 <th>Message</th>
<th>Action</th>
 </tr>';
foreach($customers as $customer){
echo '<tr onclick="opendata('.$customer->id.')">';
  $htm='<td>'.$customer->name.'</td>
 <td>'.$customer->email.'</td>
   //Important part
  <td>'.$customer->subject.'</td>
 <td>'.$customer->comment.'</td>';
echo $htm;
//Important section
echo '</tr>';
   }
echo '</table>' ;
function admin_registration_head_css() {
 $siteurl = get_option('siteurl');
$url = $siteurl . '/wp-content/plugins/' . basename(dirname(__FILE__)) . '/css/styles.css';
//Important section
$url1 = $siteurl . '/wp-content/plugins/' . basename(dirname(__FILE__)) . '/js/my.js';
echo "<link rel='stylesheet' type='text/css' href='$url' />\n";
echo '<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>';
//Important section
echo "<script type='text/javascript' src='$url1'></script>";
}
add_action('admin_head', 'admin_registration_head_css');
?>

Conclusion:

This is very important part in WP plugin development. I personally wrote the above code and it is tested by me. Please share your views in the comment section. See you on my next blog.

We Serve clients globally in diverse industries

Stay Upto Date With Our Newsletter.