Categories

Sunday, December 29, 2024
#919814419350 therichposts@gmail.com
Wordpress HooksWordpress Tricks

Best Practices – WordPress Plugin Making

How to add custom meta title and meta description in Wordpress?

Best Practices - Wordpress Plugin Making

Hello to all, welcome to therichpost.com. In this post, I will tell, Best Practices – WordPress Plugin Making.

WordPress is the top CMS in the world and I personally like it very much.

Today I am going to tell, how wordpress plugin will make with proper wordpress standards.

In this post, I will create plugin folder->  files->  classes-functions-shortcode-hooks->  zip->  uploadAdmin->  getShortcode.

Best Practices - WordPress Plugin Making

 

Here are the working and tested code for Best Practices WordPress Plugin Making:

 

1. Very First make a  folder named ‘wp-rich-text’.
2. Second, create ‘wp-rich-text.php’ file in ‘wp-rich-text’ folder and below code into it:

This is the main file of plugin, in which we declare plugin info and other methods:

<?php
/**
 * Plugin Name: Rich Plugin
 * Plugin URI: #
 * Description: #
 *
 */

define( 'RICH_PLUGIN_DIR' , plugin_dir_path( __FILE__ ));//For calling the files
if(!class_exists('RichData')){
  require_once( RICH_PLUGIN_DIR. 'class.rich.php' );
}
?>

 

3. Next, create, ‘class.rich.php’ file in wp-rich-text’ folder and below code into it:

In this file, we create class and its functions and wordpress hooks:

<?php
/*
Plugin classes
*/
class RichData{

  public static function init() {

        function custom_text( $atts ){
            return "test";
        }
        add_shortcode( 'RichText', 'custom_text' );//create shortcode to call the function into admin pages and theme's template files
    }
}
add_action( 'init', array( 'RichData', 'init' ));
?>
4. Now files and folder structure have been done now make a zip of ‘wp-rich-text’ and upload it from add plugin section into your wordpress dashboard.

 

5. To call the plugin functionality, we need to add shortcode into our wp-admin posts, pages or theme’s templates files:
// Call the shortcode into wp-admin posts and pages with below code
[RichText]


//Call the shortcode into theme's templates files with below code
echo do_shortcode('[RichText]');

 

This is done with basic plugin marking tips in wordpress. if you have any query related to it then do comment below or ask questions.

Code Is Poetry,

Thank you,

Therichpost

 

 

 

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

4 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.