{"id":9535,"date":"2024-12-02T00:01:27","date_gmt":"2024-12-01T18:31:27","guid":{"rendered":"https:\/\/weblizar.com\/blog\/?p=9535"},"modified":"2025-08-07T14:48:06","modified_gmt":"2025-08-07T09:18:06","slug":"build-wordpress-plugin-for-beginners","status":"publish","type":"post","link":"https:\/\/weblizar.com\/blog\/build-wordpress-plugin-for-beginners\/","title":{"rendered":"How to build a WordPress plugin for beginners?"},"content":{"rendered":"<p>WordPress is the most popular blogging and CMS platform out there today. Part of what has made it so successful is its ability to be extended via plugins to perform any function you desire. Developing a plugin framework is really difficult, but WordPress has one of the best solutions We\u2019ve seen to date. So how do you go about taking advantage of it and building your own plugin?<\/p>\n<p>WordPress development is done in PHP, which makes it pretty accessible as developers generally know their way around the language. Building a plugin is just a matter of creating a basic file structure and using WordPress provided functions and event hooks to drive your application.<\/p>\n<h4><a href=\"https:\/\/weblizar.com\/plugins\/jobs-portal-pro\">Jobs Portal Pro WordPress Plugin\u00a0<\/a><\/h4>\n<p><strong>The File Structure<\/strong><\/p>\n<p>All it takes to create a plugin is a single PHP file, but common practice dictates that you house your plugin and its files within a directory. To begin, create a directory to hold your plugin and give it a name matching your plugin. Then, within that directory, create your main PHP file, again naming the file with the name of your plugin:<\/p>\n<p>+ super-plugin<br \/>\n\u2013 super-plugin.php<\/p>\n<p>If your plugin is going to require any images, javascript, css, or additional PHP files, you will house those within this directory as well:<\/p>\n<p>+ super-plugin<br \/>\n+ admin<br \/>\n\u2013 super-plugin-admin.php<br \/>\n+ img<br \/>\n\u2013 icon.png<br \/>\n+ js<br \/>\n\u2013 super-plugin.js<br \/>\n\u2013 super-plugin.php<br \/>\n\u2013 readme.txt<\/p>\n<p>In this example, We\u2019ve created 3 directories, admin, img, and js to hold the additional files. The super-plugin-admin.php file will be used to provide a web interface to the plugin on the WP backend which We\u2019ll address in another post.<\/p>\n<p>Finally, if you plan on hosting your plugin in the <a href=\"https:\/\/weblizar.com\/blog\/5-best-wordpress-plugins-must-add-website\/\">WordPress plugin<\/a> directory, you\u2019ll need to include a file named readme.txt at the root of the directory. The file should follow the format detailed in this readme.txt example.<br \/>\nDefining Your Plugin<\/p>\n<p>Next, we need to define our plugin so that WP will recognize it and allow it to be installed, removed, and activated.<\/p>\n<p><strong><a href=\"https:\/\/weblizar.com\/plugins\/advanced-google-maps\">Advance Google Map Premium Plugin<\/a><\/strong><\/p>\n<p><strong>Open your main plugin file, super-plugin.php and add the following to the top of the file:<\/strong><\/p>\n<p>Replace each line with the data for your plugin. This will define your plugin details for WordPress. At a minimum you need the Plugin Name: field for the plugin to be recognized.<br \/>\nInitializing your program<\/p>\n<p>Now that WordPress knows about your plugin, it\u2019s time to make it do something. This is accomplished by using hooks and predefined WordPress functions. A hook is an event listener that is trigger based on outside events occurring. If your program needs to perform any type of setup, such as <a href=\"https:\/\/weblizar.com\/blog\/sql-database-reasons-use-mistakes-avoid\/\">database<\/a> table creation, you can tap into the plugin activation hook like so:<\/p>\n<p>\/\/SETUP<br \/>\nfunction super_plugin_install(){<br \/>\n\/\/Do some installation work<br \/>\n}<br \/>\nregister_activation_hook(__FILE__,\u2019super_plugin_install\u2019);<\/p>\n<h2 style=\"display: none;\">WordPress plugin<\/h2>\n<p>Then, when a user activates your plugin, any function that has been registered with the activation hook will be executed.<\/p>\n<p>You might also want to register some custom javascript that your plugin will need to operate. You can do this by using the add_action hook to piggyback on to another process. In this case, we\u2019re going to listen for the wp_enqueue_scripts event to trigger and let WordPress know that we want in on the script party and to please execute our function as well.<\/p>\n<p>\/\/SCRIPTS<br \/>\nfunction super_plugin_scripts(){<br \/>\nwp_register_script(\u2018super_plugin_script\u2019,plugin_dir_url( __FILE__ ).\u2019js\/super-plugin.js\u2019);<br \/>\nwp_enqueue_script(\u2018super_plugin_script\u2019);<br \/>\n}<br \/>\nadd_action(\u2018wp_enqueue_scripts\u2019,\u2019super_plugin_scripts\u2019);<\/p>\n<p>When scripts are being loaded up, your function will get executed and your script will get registered and queued to be added into the head portion of the HTML.<\/p>\n<p>Finally, you want to actually run your program. You can do this by listening to various WP hooks and waiting for an appropriate event that would trigger your code to run. If you want to run your program every time a visitor comes to your site, you can use the \u2018init\u2019 or \u2018wp_loaded\u2019 action to trigger your code:<\/p>\n<p>\/\/HOOKS<br \/>\nadd_action(\u2018init\u2019,\u2019super_plugin_init\u2019);<br \/>\n\/********************************************************\/<br \/>\n\/* FUNCTIONS<br \/>\n********************************************************\/<br \/>\nfunction super_plugin_init(){<br \/>\n\/\/do work<br \/>\nrun_sub_process();<br \/>\n}<\/p>\n<p>function run_sub_process(){<br \/>\n\/\/more work<br \/>\n}<\/p>\n<p>In this example, the super_plugin_init() function will get called on every new request and you can perform whatever logic you need. If your plugin is complex, you can add additional PHP files to build out your application and just use this initial hook to trigger the full application. A full list of the actions that run during a typical request can be found here.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WordPress is the most popular blogging and CMS platform out there today. Part of what has made it so successful is its ability to be extended via plugins to perform any function you desire. Developing a plugin framework is really difficult, but WordPress has one of the best solutions We\u2019ve seen to date. So how<\/p>\n","protected":false},"author":8,"featured_media":9550,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[6,24],"tags":[1564],"class_list":["post-9535","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-plugins","category-word-press","tag-wordpress-plugin"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to build a WordPress plugin for beginners? - Weblizar Blog<\/title>\n<meta name=\"description\" content=\"WordPress is the most popular blogging and CMS platform out there today. Part of what has made it so successful is its ability. WordPress plugin\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/weblizar.com\/blog\/build-wordpress-plugin-for-beginners\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to build a WordPress plugin for beginners? - Weblizar Blog\" \/>\n<meta property=\"og:description\" content=\"WordPress is the most popular blogging and CMS platform out there today. Part of what has made it so successful is its ability. WordPress plugin\" \/>\n<meta property=\"og:url\" content=\"https:\/\/weblizar.com\/blog\/build-wordpress-plugin-for-beginners\/\" \/>\n<meta property=\"og:site_name\" content=\"Weblizar Blog\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/www.facebook.com\/weblizarwp\" \/>\n<meta property=\"article:published_time\" content=\"2024-12-01T18:31:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-07T09:18:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/weblizar.com\/blog\/wp-content\/uploads\/2019\/01\/How-to-build-a-WordPress-plugin.jpg?fit=900%2C563&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"900\" \/>\n\t<meta property=\"og:image:height\" content=\"563\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"tarun sharma\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@weblizar\" \/>\n<meta name=\"twitter:site\" content=\"@weblizar\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"tarun sharma\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to build a WordPress plugin for beginners? - Weblizar Blog","description":"WordPress is the most popular blogging and CMS platform out there today. Part of what has made it so successful is its ability. WordPress plugin","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/weblizar.com\/blog\/build-wordpress-plugin-for-beginners\/","og_locale":"en_US","og_type":"article","og_title":"How to build a WordPress plugin for beginners? - Weblizar Blog","og_description":"WordPress is the most popular blogging and CMS platform out there today. Part of what has made it so successful is its ability. WordPress plugin","og_url":"https:\/\/weblizar.com\/blog\/build-wordpress-plugin-for-beginners\/","og_site_name":"Weblizar Blog","article_publisher":"http:\/\/www.facebook.com\/weblizarwp","article_published_time":"2024-12-01T18:31:27+00:00","article_modified_time":"2025-08-07T09:18:06+00:00","og_image":[{"width":900,"height":563,"url":"https:\/\/i0.wp.com\/weblizar.com\/blog\/wp-content\/uploads\/2019\/01\/How-to-build-a-WordPress-plugin.jpg?fit=900%2C563&ssl=1","type":"image\/jpeg"}],"author":"tarun sharma","twitter_card":"summary_large_image","twitter_creator":"@weblizar","twitter_site":"@weblizar","twitter_misc":{"Written by":"tarun sharma","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/weblizar.com\/blog\/build-wordpress-plugin-for-beginners\/#article","isPartOf":{"@id":"https:\/\/weblizar.com\/blog\/build-wordpress-plugin-for-beginners\/"},"author":{"name":"tarun sharma","@id":"https:\/\/weblizar.com\/blog\/#\/schema\/person\/71631f37679a8ea30cb7a2e295e69fe2"},"headline":"How to build a WordPress plugin for beginners?","datePublished":"2024-12-01T18:31:27+00:00","dateModified":"2025-08-07T09:18:06+00:00","mainEntityOfPage":{"@id":"https:\/\/weblizar.com\/blog\/build-wordpress-plugin-for-beginners\/"},"wordCount":778,"commentCount":0,"image":{"@id":"https:\/\/weblizar.com\/blog\/build-wordpress-plugin-for-beginners\/#primaryimage"},"thumbnailUrl":"https:\/\/weblizar.com\/blog\/wp-content\/uploads\/2019\/01\/How-to-build-a-WordPress-plugin.jpg","keywords":["WordPress Plugin"],"articleSection":["Plugins","WordPress"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/weblizar.com\/blog\/build-wordpress-plugin-for-beginners\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/weblizar.com\/blog\/build-wordpress-plugin-for-beginners\/","url":"https:\/\/weblizar.com\/blog\/build-wordpress-plugin-for-beginners\/","name":"How to build a WordPress plugin for beginners? - Weblizar Blog","isPartOf":{"@id":"https:\/\/weblizar.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/weblizar.com\/blog\/build-wordpress-plugin-for-beginners\/#primaryimage"},"image":{"@id":"https:\/\/weblizar.com\/blog\/build-wordpress-plugin-for-beginners\/#primaryimage"},"thumbnailUrl":"https:\/\/weblizar.com\/blog\/wp-content\/uploads\/2019\/01\/How-to-build-a-WordPress-plugin.jpg","datePublished":"2024-12-01T18:31:27+00:00","dateModified":"2025-08-07T09:18:06+00:00","author":{"@id":"https:\/\/weblizar.com\/blog\/#\/schema\/person\/71631f37679a8ea30cb7a2e295e69fe2"},"description":"WordPress is the most popular blogging and CMS platform out there today. Part of what has made it so successful is its ability. WordPress plugin","breadcrumb":{"@id":"https:\/\/weblizar.com\/blog\/build-wordpress-plugin-for-beginners\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/weblizar.com\/blog\/build-wordpress-plugin-for-beginners\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/weblizar.com\/blog\/build-wordpress-plugin-for-beginners\/#primaryimage","url":"https:\/\/weblizar.com\/blog\/wp-content\/uploads\/2019\/01\/How-to-build-a-WordPress-plugin.jpg","contentUrl":"https:\/\/weblizar.com\/blog\/wp-content\/uploads\/2019\/01\/How-to-build-a-WordPress-plugin.jpg","width":900,"height":563,"caption":"WordPress plugin"},{"@type":"BreadcrumbList","@id":"https:\/\/weblizar.com\/blog\/build-wordpress-plugin-for-beginners\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/weblizar.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to build a WordPress plugin for beginners?"}]},{"@type":"WebSite","@id":"https:\/\/weblizar.com\/blog\/#website","url":"https:\/\/weblizar.com\/blog\/","name":"Weblizar Blog","description":"Update yourself with all the latest tech news revolving around wordpress all at one place","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/weblizar.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/weblizar.com\/blog\/#\/schema\/person\/71631f37679a8ea30cb7a2e295e69fe2","name":"tarun sharma","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/026a42b8cec5a7d671fb97d2b66dad482246e2825405e2234ec50611ecda0c69?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/026a42b8cec5a7d671fb97d2b66dad482246e2825405e2234ec50611ecda0c69?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/026a42b8cec5a7d671fb97d2b66dad482246e2825405e2234ec50611ecda0c69?s=96&d=mm&r=g","caption":"tarun sharma"}}]}},"_links":{"self":[{"href":"https:\/\/weblizar.com\/blog\/wp-json\/wp\/v2\/posts\/9535","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/weblizar.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/weblizar.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/weblizar.com\/blog\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/weblizar.com\/blog\/wp-json\/wp\/v2\/comments?post=9535"}],"version-history":[{"count":0,"href":"https:\/\/weblizar.com\/blog\/wp-json\/wp\/v2\/posts\/9535\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/weblizar.com\/blog\/wp-json\/wp\/v2\/media\/9550"}],"wp:attachment":[{"href":"https:\/\/weblizar.com\/blog\/wp-json\/wp\/v2\/media?parent=9535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/weblizar.com\/blog\/wp-json\/wp\/v2\/categories?post=9535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/weblizar.com\/blog\/wp-json\/wp\/v2\/tags?post=9535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}