{"id":583,"date":"2014-02-20T16:15:50","date_gmt":"2014-02-20T16:15:50","guid":{"rendered":"http:\/\/www.webmastersun.com\/blog\/?p=583"},"modified":"2014-02-22T03:58:17","modified_gmt":"2014-02-22T03:58:17","slug":"how-to-write-a-simple-wordpress-plugin","status":"publish","type":"post","link":"https:\/\/www.webmastersun.com\/blog\/how-to-write-a-simple-wordpress-plugin\/","title":{"rendered":"How to Write a Simple WordPress Plugin"},"content":{"rendered":"<p>When you have a good WordPress blog and plugins are installed from the plugin&#8217;s library,\u00a0 you can create your own simple WordPress plugin. How you want to customize it depends on your needs. Here&#8217;s an article outlining the steps necessary on <strong>How to Write a Simple WordPress Plugin<\/strong>!<\/p>\n<p>The main factor of a WP plugin are the 2 functions listed below (known as &#8220;<strong>hooks<\/strong>&#8220;)<br \/>\nadd_action($tag,$function);<br \/>\nadd_filter($tag,$function);<\/p>\n<p><strong>The definition of the two important functions are:<\/strong><br \/>\n<strong>Add_action<\/strong>: Invoke a function in one or more locations in WP enforcement process.<br \/>\n<strong>Add_filter<\/strong>: Used for filtering data or replacing content and returning results for web browser display.<br \/>\nYou should refer to the WordPress Codex for a more detailed explanation.<\/p>\n<h3>Information about Plugin<\/h3>\n<p>Showing your text when the plugin is activated in the WordPress dashboard.<\/p>\n<p>First, you need to create a file webcome-to-webmastersun.php and add the code to it.<\/p>\n<pre>&lt;?php\r\n\/*\r\nPlugin Name: Welcome to Webmaster Sun\r\nPlugin URI: https:\/\/www.webmastersun.com\r\nDescription: Say \"Welcome to Webmaster Sun\" at wherever you want\r\nVersion: 1.0\r\nAuthor: Webmaster Sun\r\nAuthor URI: https:\/\/www.webmastersun.com\r\nLicense: GPL\r\n*\/\r\n?&gt;<\/pre>\n<p>Copy this file into wordpress &gt; wp-content &gt; plugins and go to Admin &gt; Plugins and see what is showing.<\/p>\n<p><a href=\"https:\/\/www.webmastersun.com\/blog\/wp-content\/uploads\/2014\/02\/simple_wordpress_plugin_1.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-588\" alt=\"simple_wordpress_plugin_1\" src=\"https:\/\/www.webmastersun.com\/blog\/wp-content\/uploads\/2014\/02\/simple_wordpress_plugin_1.png\" width=\"680\" height=\"194\" srcset=\"https:\/\/www.webmastersun.com\/blog\/wp-content\/uploads\/2014\/02\/simple_wordpress_plugin_1.png 680w, https:\/\/www.webmastersun.com\/blog\/wp-content\/uploads\/2014\/02\/simple_wordpress_plugin_1-300x85.png 300w\" sizes=\"(max-width: 680px) 100vw, 680px\" \/><\/a><\/p>\n<h3>How it works<\/h3>\n<p>The plugin will show &#8220;Welcome to Webmaster Sun, A great forum for discussing about SEO, Web Development and Internet Marketing Online!!!&#8221; on any page templates that you want.<\/p>\n<p><strong>Activate plugin and add this code to the page templates you want them to appear:<\/strong><\/p>\n<pre>&lt;?php\r\nif(function_exists('welcome_to_webmastersun')) {\r\nwelcome_to_webmastersun();\r\n}\r\n?&gt;<\/pre>\n<p>Ok, now let&#8217;s go with the detail.<\/p>\n<p><strong>Complete code:<\/strong><\/p>\n<pre>&lt;?php\r\n\/*\r\nPlugin Name: Welcome to Webmaster Sun\r\nPlugin URI: https:\/\/www.webmastersun.com\r\nDescription: Say \"Welcome to Webmaster Sun\" at wherever you want\r\nVersion: 1.0\r\nAuthor: Webmaster Sun\r\nAuthor URI: https:\/\/www.webmastersun.com\r\nLicense: GPL\r\n*\/\r\n\/* This calls welcome_to_webmastersun() function when this function called in your wordpress\r\nfile.*\/\r\nfunction welcome_to_webmastersun()\r\n{\r\necho \"Welcome to Webmaster Sun, A great forum for discussing about SEO, Web Development and\r\nInternet Marketing Online!!!\";\r\n}\r\n?&gt;<\/pre>\n<p><strong>Explanation<\/strong>: When your pages are being shown then the function welcome_to_webmastersun() will be called and return its value.<\/p>\n<h3>This is the result we will get:<\/h3>\n<p><a href=\"https:\/\/www.webmastersun.com\/blog\/wp-content\/uploads\/2014\/02\/simple_wordpress_plugin_pic.png\"><img loading=\"lazy\" class=\"alignnone  wp-image-590\" alt=\"simple_wordpress_plugin_pic\" src=\"https:\/\/www.webmastersun.com\/blog\/wp-content\/uploads\/2014\/02\/simple_wordpress_plugin_pic.png\" width=\"680\" height=\"221\" srcset=\"https:\/\/www.webmastersun.com\/blog\/wp-content\/uploads\/2014\/02\/simple_wordpress_plugin_pic.png 680w, https:\/\/www.webmastersun.com\/blog\/wp-content\/uploads\/2014\/02\/simple_wordpress_plugin_pic-300x97.png 300w\" sizes=\"(max-width: 680px) 100vw, 680px\" \/><\/a><\/p>\n<p>You can customize this plugin to do anything. For example, replace strings in content, remove unexpected characters or make titles capitalized&#8230;etc with <strong>add_action<\/strong> and <strong>add_filter<\/strong> function of plugin.<\/p>\n<p>Remember to activate the plugin to see your result.<\/p>\n<p>Good luck!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you have a good WordPress blog and plugins are installed from the plugin&#8217;s library,\u00a0 you can create your own simple WordPress plugin. How you want to customize it depends on your needs. Here&#8217;s an article outlining the steps necessary on How to Write a Simple WordPress Plugin! The main factor of a WP plugin [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":587,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[58],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v17.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Write a Simple WordPress Plugin - Webmaster Sun Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webmastersun.com\/blog\/how-to-write-a-simple-wordpress-plugin\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Write a Simple WordPress Plugin - Webmaster Sun Blog\" \/>\n<meta property=\"og:description\" content=\"When you have a good WordPress blog and plugins are installed from the plugin&#8217;s library,\u00a0 you can create your own simple WordPress plugin. How you want to customize it depends on your needs. Here&#8217;s an article outlining the steps necessary on How to Write a Simple WordPress Plugin! The main factor of a WP plugin [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webmastersun.com\/blog\/how-to-write-a-simple-wordpress-plugin\/\" \/>\n<meta property=\"og:site_name\" content=\"Webmaster Sun Blog\" \/>\n<meta property=\"article:published_time\" content=\"2014-02-20T16:15:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-02-22T03:58:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webmastersun.com\/blog\/wp-content\/uploads\/2014\/02\/how-to-create-a-simple-wordpress-plugin.png\" \/>\n\t<meta property=\"og:image:width\" content=\"225\" \/>\n\t<meta property=\"og:image:height\" content=\"225\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tommy\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webmastersun.com\/blog\/#website\",\"url\":\"https:\/\/www.webmastersun.com\/blog\/\",\"name\":\"Webmaster Sun Blog\",\"description\":\"Blogging Tips to help you make money online\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webmastersun.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.webmastersun.com\/blog\/how-to-write-a-simple-wordpress-plugin\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/www.webmastersun.com\/blog\/wp-content\/uploads\/2014\/02\/how-to-create-a-simple-wordpress-plugin.png\",\"contentUrl\":\"https:\/\/www.webmastersun.com\/blog\/wp-content\/uploads\/2014\/02\/how-to-create-a-simple-wordpress-plugin.png\",\"width\":225,\"height\":225,\"caption\":\"how-to-create-a-simple-wordpress-plugin\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webmastersun.com\/blog\/how-to-write-a-simple-wordpress-plugin\/#webpage\",\"url\":\"https:\/\/www.webmastersun.com\/blog\/how-to-write-a-simple-wordpress-plugin\/\",\"name\":\"How to Write a Simple WordPress Plugin - Webmaster Sun Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.webmastersun.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webmastersun.com\/blog\/how-to-write-a-simple-wordpress-plugin\/#primaryimage\"},\"datePublished\":\"2014-02-20T16:15:50+00:00\",\"dateModified\":\"2014-02-22T03:58:17+00:00\",\"author\":{\"@id\":\"https:\/\/www.webmastersun.com\/blog\/#\/schema\/person\/441faf493750eb1507f97d50ea9cd742\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.webmastersun.com\/blog\/how-to-write-a-simple-wordpress-plugin\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webmastersun.com\/blog\/how-to-write-a-simple-wordpress-plugin\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webmastersun.com\/blog\/how-to-write-a-simple-wordpress-plugin\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webmastersun.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Write a Simple WordPress Plugin\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webmastersun.com\/blog\/#\/schema\/person\/441faf493750eb1507f97d50ea9cd742\",\"name\":\"Tommy\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.webmastersun.com\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b17c25a7f242f8dc0328ed5929c512fd?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b17c25a7f242f8dc0328ed5929c512fd?s=96&d=mm&r=g\",\"caption\":\"Tommy\"},\"url\":\"https:\/\/www.webmastersun.com\/blog\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Write a Simple WordPress Plugin - Webmaster Sun Blog","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:\/\/www.webmastersun.com\/blog\/how-to-write-a-simple-wordpress-plugin\/","og_locale":"en_US","og_type":"article","og_title":"How to Write a Simple WordPress Plugin - Webmaster Sun Blog","og_description":"When you have a good WordPress blog and plugins are installed from the plugin&#8217;s library,\u00a0 you can create your own simple WordPress plugin. How you want to customize it depends on your needs. Here&#8217;s an article outlining the steps necessary on How to Write a Simple WordPress Plugin! The main factor of a WP plugin [&hellip;]","og_url":"https:\/\/www.webmastersun.com\/blog\/how-to-write-a-simple-wordpress-plugin\/","og_site_name":"Webmaster Sun Blog","article_published_time":"2014-02-20T16:15:50+00:00","article_modified_time":"2014-02-22T03:58:17+00:00","og_image":[{"width":225,"height":225,"url":"https:\/\/www.webmastersun.com\/blog\/wp-content\/uploads\/2014\/02\/how-to-create-a-simple-wordpress-plugin.png","type":"image\/png"}],"twitter_misc":{"Written by":"Tommy","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/www.webmastersun.com\/blog\/#website","url":"https:\/\/www.webmastersun.com\/blog\/","name":"Webmaster Sun Blog","description":"Blogging Tips to help you make money online","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webmastersun.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https:\/\/www.webmastersun.com\/blog\/how-to-write-a-simple-wordpress-plugin\/#primaryimage","inLanguage":"en-US","url":"https:\/\/www.webmastersun.com\/blog\/wp-content\/uploads\/2014\/02\/how-to-create-a-simple-wordpress-plugin.png","contentUrl":"https:\/\/www.webmastersun.com\/blog\/wp-content\/uploads\/2014\/02\/how-to-create-a-simple-wordpress-plugin.png","width":225,"height":225,"caption":"how-to-create-a-simple-wordpress-plugin"},{"@type":"WebPage","@id":"https:\/\/www.webmastersun.com\/blog\/how-to-write-a-simple-wordpress-plugin\/#webpage","url":"https:\/\/www.webmastersun.com\/blog\/how-to-write-a-simple-wordpress-plugin\/","name":"How to Write a Simple WordPress Plugin - Webmaster Sun Blog","isPartOf":{"@id":"https:\/\/www.webmastersun.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webmastersun.com\/blog\/how-to-write-a-simple-wordpress-plugin\/#primaryimage"},"datePublished":"2014-02-20T16:15:50+00:00","dateModified":"2014-02-22T03:58:17+00:00","author":{"@id":"https:\/\/www.webmastersun.com\/blog\/#\/schema\/person\/441faf493750eb1507f97d50ea9cd742"},"breadcrumb":{"@id":"https:\/\/www.webmastersun.com\/blog\/how-to-write-a-simple-wordpress-plugin\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webmastersun.com\/blog\/how-to-write-a-simple-wordpress-plugin\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.webmastersun.com\/blog\/how-to-write-a-simple-wordpress-plugin\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webmastersun.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Write a Simple WordPress Plugin"}]},{"@type":"Person","@id":"https:\/\/www.webmastersun.com\/blog\/#\/schema\/person\/441faf493750eb1507f97d50ea9cd742","name":"Tommy","image":{"@type":"ImageObject","@id":"https:\/\/www.webmastersun.com\/blog\/#personlogo","inLanguage":"en-US","url":"https:\/\/secure.gravatar.com\/avatar\/b17c25a7f242f8dc0328ed5929c512fd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b17c25a7f242f8dc0328ed5929c512fd?s=96&d=mm&r=g","caption":"Tommy"},"url":"https:\/\/www.webmastersun.com\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webmastersun.com\/blog\/wp-json\/wp\/v2\/posts\/583"}],"collection":[{"href":"https:\/\/www.webmastersun.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webmastersun.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webmastersun.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webmastersun.com\/blog\/wp-json\/wp\/v2\/comments?post=583"}],"version-history":[{"count":0,"href":"https:\/\/www.webmastersun.com\/blog\/wp-json\/wp\/v2\/posts\/583\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webmastersun.com\/blog\/wp-json\/wp\/v2\/media\/587"}],"wp:attachment":[{"href":"https:\/\/www.webmastersun.com\/blog\/wp-json\/wp\/v2\/media?parent=583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webmastersun.com\/blog\/wp-json\/wp\/v2\/categories?post=583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webmastersun.com\/blog\/wp-json\/wp\/v2\/tags?post=583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}