{"id":34,"date":"2023-06-30T17:23:57","date_gmt":"2023-06-30T09:23:57","guid":{"rendered":"https:\/\/clifford.io\/blog\/?p=34"},"modified":"2024-07-24T21:43:27","modified_gmt":"2024-07-24T13:43:27","slug":"create-a-basic-wordpress-plugin-complete-guide","status":"publish","type":"post","link":"https:\/\/clifford.io\/blog\/create-a-basic-wordpress-plugin-complete-guide\/","title":{"rendered":"How to Create a Basic WordPress Plugin &#8211; A Complete Guide"},"content":{"rendered":"\n<p>Hello! The goal of this post is to show you step-by-step details on how to create a basic WordPress plugin that is super simple, yet fully-functional. This can be a boilerplate or a starting point for all your plugin-creation journey! Anyone with a basic knowledge of PHP, Javascript and CSS should be able to do this. By the end of this post, you will have created a custom plugin for WordPress with these functionalities:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>An options page in the admin panel that allows you to save some settings or content to the WordPress database.<\/li>\n\n\n\n<li>A shortcode that allows you to display the content saved in the WordPress database, or otherwise some predefined default text.<\/li>\n\n\n\n<li>A way to add or <strong>enqueue<\/strong> (WordPress terminology) your plugin&#8217;s Javascript and CSS.<\/li>\n<\/ul>\n\n\n\n<p>We will also test our plugin after the coding is done. Let&#8217;s start!<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_60 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\" role=\"button\"><label for=\"item-69df442fc0216\" ><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input aria-label=\"Toggle\" aria-label=\"item-69df442fc0216\"  type=\"checkbox\" id=\"item-69df442fc0216\"><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/clifford.io\/blog\/create-a-basic-wordpress-plugin-complete-guide\/#Step_1_Create_the_plugin_folder_and_files\" title=\"Step 1 : Create the plugin folder and files:\">Step 1 : Create the plugin folder and files:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/clifford.io\/blog\/create-a-basic-wordpress-plugin-complete-guide\/#Step_2_Plugin_activation_and_deactivation_hooks_my-pluginphp\" title=\"Step 2 : Plugin activation and deactivation hooks (my-plugin.php):\">Step 2 : Plugin activation and deactivation hooks (my-plugin.php):<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/clifford.io\/blog\/create-a-basic-wordpress-plugin-complete-guide\/#Step_3_Admin_options_page_adminoptions-pagephp\" title=\"Step 3 : Admin options page (admin\/options-page.php)\">Step 3 : Admin options page (admin\/options-page.php)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/clifford.io\/blog\/create-a-basic-wordpress-plugin-complete-guide\/#Step_4_Enqueue_scripts_includesscriptsphp\" title=\"Step 4 : Enqueue scripts (includes\/scripts.php):\">Step 4 : Enqueue scripts (includes\/scripts.php):<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/clifford.io\/blog\/create-a-basic-wordpress-plugin-complete-guide\/#Step_5_Shortcode_includesshortcodesphp\" title=\"Step 5 : Shortcode (includes\/shortcodes.php):\">Step 5 : Shortcode (includes\/shortcodes.php):<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/clifford.io\/blog\/create-a-basic-wordpress-plugin-complete-guide\/#Step_6_The_plugins_style_file_includescssstylecss\" title=\"Step 6 : The plugin&#8217;s style file (includes\/css\/style.css):\">Step 6 : The plugin&#8217;s style file (includes\/css\/style.css):<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/clifford.io\/blog\/create-a-basic-wordpress-plugin-complete-guide\/#Step_7_Uploading_the_plugin_directory_to_%E2%80%9Cwp-contentplugins%E2%80%9D_directory\" title=\"Step 7 : Uploading the plugin directory to &#8220;wp-content\/plugins\/&#8221; directory\">Step 7 : Uploading the plugin directory to &#8220;wp-content\/plugins\/&#8221; directory<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/clifford.io\/blog\/create-a-basic-wordpress-plugin-complete-guide\/#Step_8_Login_to_your_WordPress_admin_and_activate_plugin\" title=\"Step 8 : Login to your WordPress admin and activate plugin\">Step 8 : Login to your WordPress admin and activate plugin<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/clifford.io\/blog\/create-a-basic-wordpress-plugin-complete-guide\/#Step_9_Go_to_your_plugins_option_settings_page\" title=\"Step 9 : Go to your plugin&#8217;s option settings page\">Step 9 : Go to your plugin&#8217;s option settings page<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/clifford.io\/blog\/create-a-basic-wordpress-plugin-complete-guide\/#Step_10_Setting_up_the_shortcode\" title=\"Step 10 : Setting up the shortcode\">Step 10 : Setting up the shortcode<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_1_Create_the_plugin_folder_and_files\"><\/span>Step 1 : <strong>Create the plugin folder and files:<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>On your computer, create a new folder. Let&#8217;s call it &#8220;my-plugin&#8221;. You will be putting all your code files in this folder. This folder will be uploaded to your WordPress&#8217; plugin folder when you are done. More on this later.<\/li>\n\n\n\n<li>Inside the &#8220;my-plugin&#8221; folder, create the following files:\n<ul class=\"wp-block-list\">\n<li><code>my-plugin.php<\/code>: Main plugin file.<\/li>\n\n\n\n<li><code>admin\/options-page.php<\/code>: Admin options page template.<\/li>\n\n\n\n<li><code>includes\/scripts.php<\/code>: Contains functions to enqueue scripts and styles.<\/li>\n\n\n\n<li><code>includes\/shortcodes.php<\/code>: Contains shortcode functions.<\/li>\n\n\n\n<li><code>includes\/css\/style.css:<\/code> Contains the style for your shortcode output.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_2_Plugin_activation_and_deactivation_hooks_my-pluginphp\"><\/span>Step 2 : <strong>Plugin activation and deactivation hooks (my-plugin.php):<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In the &#8220;my-plugin.php&#8221; file, define the header information for your plugin. For example, the plugin name, description, author, and version information.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Hook into the <code>activate_plugin<\/code> and <code>deactivate_plugin<\/code> actions to perform necessary setup and cleanup tasks.<\/li>\n\n\n\n<li>Include the other plugin files required for the admin options page, scripts shortcode functionality at the bottom of this file.<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/*\nPlugin Name: My Plugin Name\nDescription: Description of my plugin.\nAuthor: My Name\nVersion: 1.0\n*\/\n\nregister_activation_hook(__FILE__, 'my_plugin_activation_function');\nregister_deactivation_hook(__FILE__, 'my_plugin_deactivation_function');\n\nfunction my_plugin_activation_function() {\n  \/\/ Perform activation tasks here\n  \/\/ This can be any setup tasks that your plugin should perform when it is activated\n}\n\nfunction my_plugin_deactivation_function() {\n  \/\/ Perform deactivation tasks here\n  \/\/ This can be any clean-up task that your plugin can perform once deactivated\n}\n\nrequire_once(plugin_dir_path(__FILE__) . 'admin\/options-page.php');\nrequire_once(plugin_dir_path(__FILE__) . 'includes\/scripts.php');\nrequire_once(plugin_dir_path(__FILE__) . 'includes\/shortcodes.php');<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_3_Admin_options_page_adminoptions-pagephp\"><\/span>Step 3 : <strong>Admin options page (admin\/options-page.php)<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Next, we will create a basic options page that can save ONE piece of text to the WordPress database using the WordPress Settings API.<\/li>\n\n\n\n<li>We add a single text field and a save button to save the text with the <code>register_setting()<\/code> and <code>add_settings_field()<\/code> functions.<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nfunction my_plugin_options_page() {\n  \/\/ Create the options page HTML\n?>\n  &lt;div class=\"wrap\">\n    &lt;h1>My Plugin Settings&lt;\/h1>\n    &lt;form method=\"post\" action=\"options.php\">\n      &lt;?php settings_fields('my_plugin_options_group'); ?>\n      &lt;?php do_settings_sections('my_plugin_options_page'); ?>\n      &lt;?php submit_button(); ?>\n    &lt;\/form>\n  &lt;\/div>\n&lt;?php\n}\n\nfunction my_plugin_settings_init() {\n  \/\/ Register settings\n  register_setting('my_plugin_options_group', 'my_plugin_option_name');\n\n  \/\/ Add sections and fields\n  add_settings_section('my_plugin_options_section', 'General Settings', 'my_plugin_section_callback', 'my_plugin_options_page');\n  add_settings_field('my_plugin_option_name', 'Option Name', 'my_plugin_option_name_callback', 'my_plugin_options_page', 'my_plugin_options_section');\n}\n\nfunction my_plugin_section_callback() {\n  \/\/ Handle any callback if needed\n}\n\nfunction my_plugin_option_name_callback() {\n  \/\/ Output HTML for the field\n  $option_value = get_option('my_plugin_option_name');\n  echo \"&lt;input type='text' name='my_plugin_option_name' value='$option_value' \/>\";\n}\n\nadd_action('admin_menu', 'my_plugin_add_admin_menu');\nadd_action('admin_init', 'my_plugin_settings_init');\n\nfunction my_plugin_add_admin_menu() {\n  add_options_page('Your Plugin', 'Your Plugin', 'manage_options', 'my_plugin_options_page', 'my_plugin_options_page');\n}<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_4_Enqueue_scripts_includesscriptsphp\"><\/span>Step 4 : <strong>Enqueue scripts (includes\/scripts.php):<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Next, we will need to enqueue our plugin&#8217;s Javascript and CSS files, if any. This ensures that when our plugin is activated, the scripts and styles will be activated and vice versa.<\/li>\n\n\n\n<li>Create a function to enqueue external JavaScript files and a CSS file for your plugin.<\/li>\n\n\n\n<li>The external.js file can be any external libraries that your plugin depends on.<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nfunction my_plugin_enqueue_scripts() {\n  \/\/ Enqueue external JavaScript\n  wp_enqueue_script('my-plugin-script', 'https:\/\/example.com\/external.js', array(), '1.0', true);\n  \n  \/\/ Enqueue CSS file\n  wp_enqueue_style('my-plugin-style', plugin_dir_url(__FILE__) . 'css\/style.css', array(), '1.0', 'all');\n}\n\nadd_action('wp_enqueue_scripts', 'my_plugin_enqueue_scripts');<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_5_Shortcode_includesshortcodesphp\"><\/span>Step 5 : <strong>Shortcode (includes\/shortcodes.php)<\/strong>:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Next, we want to create a shortcode function that outputs the desired plugin JavaScript and HTML code on our pages or posts.<\/li>\n\n\n\n<li>In this step, we named our short code as &#8220;my_plugin_shortcode&#8221;. You can however call it anything you like. This shortcode name will be used to display your plugin content later.<\/li>\n\n\n\n<li>The plugin will also enable you to pass a &#8220;text&#8221; attribute as a default. The default text will appear if you did not save any text via the settings API. More on this later.<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nfunction my_plugin_shortcode($atts) {\n  \/\/ Extract the \"text\" argument from the shortcode attributes\n  $atts = shortcode_atts(array(\n    'text' => 'Some Default Text',\n  ), $atts);\n\n  \/\/ Output JavaScript code with the provided text\n  ob_start();\n?>\n  &lt;script>\n    \/\/ JavaScript code here\n    var text = \"&lt;?php echo esc_js($atts['text']); ?>\";\n    console.log(text);\n  &lt;\/script>\n  &lt;p class=\"my-plugin-para\">\n    &lt;?php \n        $my_plugin_option = get_option('my_plugin_option_name');\n        if ($my_plugin_option != ''){\n            \/\/ echo the text set in the option\n            echo $my_plugin_option;\n        }else{\n            \/\/ echo the default text\n            echo $atts['text'];\n        }\n        \n    ?>\n  &lt;\/p>\n&lt;?php\n  return ob_get_clean();\n}\nadd_shortcode('my_plugin_shortcode', 'my_plugin_shortcode');<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_6_The_plugins_style_file_includescssstylecss\"><\/span>Step 6 : The plugin&#8217;s style file (includes\/css\/style.css):<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To round up the coding part of the work, we will add a basic style to the plugin &#8211; a yellow box encapsulating the line of text output by the plugin. Let&#8217;s add the CSS:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"css\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">.my-plugin-para {\n  padding:10px;\n  background:yellow;\n  color:#000000;\n}<\/pre>\n\n\n\n<p>That&#8217;s it. We are ready to test this plugin!<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_7_Uploading_the_plugin_directory_to_%E2%80%9Cwp-contentplugins%E2%80%9D_directory\"><\/span>Step 7 : Uploading the plugin directory to &#8220;wp-content\/plugins\/&#8221; directory<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This step may differ depending on your setup. So I will not delve deep into this. Upload your &#8220;my-plugin&#8221; directory to the &#8220;wp-content\/plugins\/&#8221; directory. Done? Let&#8217;s test!<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_8_Login_to_your_WordPress_admin_and_activate_plugin\"><\/span>Step 8 : Login to your WordPress admin and activate plugin<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Go to your &#8220;Plugins&#8221; menu and activate your plugin. Notice that the name, description, version and author information that you set up in step 2 is displayed on this page.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"342\" src=\"https:\/\/clifford.io\/blog\/wp-content\/uploads\/2023\/06\/wp-plugins-page.png\" alt=\"\" class=\"wp-image-35\" srcset=\"https:\/\/clifford.io\/blog\/wp-content\/uploads\/2023\/06\/wp-plugins-page.png 800w, https:\/\/clifford.io\/blog\/wp-content\/uploads\/2023\/06\/wp-plugins-page-300x128.png 300w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_9_Go_to_your_plugins_option_settings_page\"><\/span>Step 9 : Go to your plugin&#8217;s option settings page<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To recap, we created a single field to store our plugin text in step 3. Let&#8217;s visit that page now. In your WordPress Admin, on the left column, click on &#8220;Settings&#8221;, and then &#8220;My Plugin&#8221;. This is where your plugin&#8217;s option page entry point is when we set that up in step 3. In the &#8220;Plugin Text&#8221; field presented on the page, try typing in &#8220;This is my plugin!&#8221; and click &#8220;Save Changes&#8221;. Your text should be saved.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"540\" src=\"https:\/\/clifford.io\/blog\/wp-content\/uploads\/2023\/06\/wp-plugin-settings-page.png\" alt=\"\" class=\"wp-image-36\" srcset=\"https:\/\/clifford.io\/blog\/wp-content\/uploads\/2023\/06\/wp-plugin-settings-page.png 800w, https:\/\/clifford.io\/blog\/wp-content\/uploads\/2023\/06\/wp-plugin-settings-page-300x203.png 300w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_10_Setting_up_the_shortcode\"><\/span>Step 10 : Setting up the shortcode<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>A shortcode is simply a custom WordPress tag that can display content from a plugin or theme. It puts the control of where to display the content in the author&#8217;s hands since shortcodes can be placed anywhere on a page or post. Let&#8217;s test our example. Go to the WordPress Admin &#8220;Posts&#8221; menu, and create a new post. Give it a title. I&#8217;ll call mine &#8220;This is a plugin test&#8221;.<\/p>\n\n\n\n<p>Next, on a new block, click on the &#8220;+&#8221; and select &#8220;Shortcode&#8221;.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"367\" src=\"https:\/\/clifford.io\/blog\/wp-content\/uploads\/2023\/06\/wp-shortcode.png\" alt=\"create a basic wordpress plugin - add shortcode\" class=\"wp-image-38\" srcset=\"https:\/\/clifford.io\/blog\/wp-content\/uploads\/2023\/06\/wp-shortcode.png 800w, https:\/\/clifford.io\/blog\/wp-content\/uploads\/2023\/06\/wp-shortcode-300x138.png 300w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<p>Add in your plugin shortcode. Recall that we named it &#8220;my_plugin_shortcode&#8221; in step 5. You can always name it more intuitively to suit your needs. Using square brackets, we will put in our shortcode like this. Similar to HTML, there is an opening and a closing tag.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"317\" src=\"https:\/\/clifford.io\/blog\/wp-content\/uploads\/2023\/06\/wp-enter-shortcode.png\" alt=\"create a basic wordpress plugin - shortcode\" class=\"wp-image-39\" srcset=\"https:\/\/clifford.io\/blog\/wp-content\/uploads\/2023\/06\/wp-enter-shortcode.png 800w, https:\/\/clifford.io\/blog\/wp-content\/uploads\/2023\/06\/wp-enter-shortcode-300x119.png 300w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<p>Once done, click on save and go to preview the page. You should able to see your shortcode display in a yellow box (see the CSS set up in step 6) on your post!<\/p>\n\n\n\n<p>Now, one last thing&#8230;go back to your plugin&#8217;s &#8220;Settings&#8221; and remove the text that you saved earlier. Then, go back to your post page. The default fallback text &#8220;Some Default Text&#8221; set on the shortcode in step 5 should be displayed.<\/p>\n\n\n\n<p>That&#8217;s all! You can find the complete source code for this tutorial on <a href=\"https:\/\/github.com\/cliffordtky\/wp-plugin-boilerplate\" target=\"_blank\" rel=\"noreferrer noopener\">Github<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The goal of this post is to show you step-by-step details on how to create a fully-functional (but basic) Wordpress plugin. This can be a boilerplate or a starting point for all your plugin-creation journey!<\/p>\n","protected":false},"author":1,"featured_media":42,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[14,6],"class_list":["post-34","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-development","tag-plugin","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/clifford.io\/blog\/wp-json\/wp\/v2\/posts\/34","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/clifford.io\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/clifford.io\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/clifford.io\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/clifford.io\/blog\/wp-json\/wp\/v2\/comments?post=34"}],"version-history":[{"count":5,"href":"https:\/\/clifford.io\/blog\/wp-json\/wp\/v2\/posts\/34\/revisions"}],"predecessor-version":[{"id":109,"href":"https:\/\/clifford.io\/blog\/wp-json\/wp\/v2\/posts\/34\/revisions\/109"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/clifford.io\/blog\/wp-json\/wp\/v2\/media\/42"}],"wp:attachment":[{"href":"https:\/\/clifford.io\/blog\/wp-json\/wp\/v2\/media?parent=34"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/clifford.io\/blog\/wp-json\/wp\/v2\/categories?post=34"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/clifford.io\/blog\/wp-json\/wp\/v2\/tags?post=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}