How To Create Plugin In WordPress With Example
Last Updated : Mar 11, 2024
In this article we will show you the solution of how to create plugin in WordPress with example, WordPress plugins can assist you in getting better your website. Numerous free ones are available, and you can even make your own unique WordPress plugins.
WordPress plugins function similarly to apps on your WordPress website.
WordPress plugins can be installed to add new features, just like mobile apps. You can also put your plugin through its paces on a test website.
Step By Step Guide On How To Create Plugin In WordPress With Example :-
Header code -
function tc_follow_us($content) { // Only execute this when only one post is visible. if (is_single() ) { // Message to be displayed after the post // Include URLs in your Twitter and Facebook profiles. $content.= '<p class="follow-us">If you liked this article, then please follow us on <a href="http://twitter.com/talkerscode" title="TalkersCode on Twitter" target="_blank" rel="nofollow">Twitter</a> and <a href="https://www.facebook.com/talkerscode" title="TalkersCode on Facebook" target="_blank" rel="nofollow">Facebook</a>.</p>'; } // Return the content return $content; } // Connect our function to the content filter in WordPress. add_filter('the_content', 'tc_follow_us'); functions.php code: - <?php /* Plugin Name: TalkersCode Plugin Tutorial. Plugin URI: https://www.talkerscode.com. Description: We create TalkersCode plugin. Version: 1.0 Author: TalkersCode. Author URI: https://www.talkerscode.com. License: GPL2 License URI: https://www.gnu.org/licenses/gpl-2.0.html. Text Domain: TalkersCode-tutorial. Domain Path: /languages */
- Create a new directory with a name like "tc-plugin" or "my-first-plugin" on their desktop or in your documents folder as the first step.
- Next, in your text editor, create a new file called tc-plugin.php or my-first-plugin.php and save it in your plugin folder. You are entirely free to choose the filename; only the .php extension is required.
- You must open that PHP file in your text editor.
- Your plugin file needs a plugin header, which you must include first. This comment block merely provides WordPress with information about your plugin's name, version, website, plugin author, and other details.
- The plugin code can then be added below the header after the header has been added.
- In this tutorial, we'll show you how to make a straightforward plugin that asks readers to follow us all on Twitter just at end of each article.
- Paste and copy the code below the header block of your plugin.
- Before saving your changes, don't forget to replace the URLs for your Twitter and Facebook profiles with your own.
- Create the zip file again for plugin folder on the desktop of your computer right away.
- Mac users can compress the wpb-plugin-tutorial folder by right clicking on it and selecting 'Compress tc-plugin'. Use the Send to »Compressed folder option from the context menu when using Windows to select the folder.
- Now that we've built the plugin, it's time to put it to the test.
- Go to your website's WordPress admin area and navigate to the Plugins »Add New site.
- To upload your plugin, click the 'Upload Plugin' button at the top. This displays a plugin upload box.
- Select a zip file visitor just created by clicking the Choose File button. Then, to upload but also install the plugin, click the Install Now button.
- After you've installed it, activate the plugin.
- You can now view a plugin in action by visiting your website. The new paragraph will be visible there at end of all their single posts.
Conclusion :-
As a result, we have successfully learned how to create plugin in wordpress with example.
To create a plugin, you'll need a basic understanding of coding languages such as PHP, CSS, HTML, and JavaScript.
You must have a local development environment in place once testing your WordPress installation on your computer.
I hope this article on how to create plugin in WordPress with example helps you and the steps and method mentioned above are easy to follow and implement.