How To Create A Plugin For A Specific Site For WordPress

3 minutes read

When I redesigned this site, I discovered my big mistake on the old version. A lot of functionality has been added over time to the functions.php file of the old theme. This not only increased the file size but also increased the likelihood of errors on the site each time you make changes to it. Therefore, it was decided to create a plugin for the entire site (plugin with hooks from functions.php), which was not tied to the template. What kind of plugin it is, why it is needed, and how to create the same for your site you will learn from this article.

What Kind Of Plugin Is This?

A Site-Specific plugin is a specific place for adding snippets that you find on the Internet, and these snippets are not tied to the current site template. In other words:

From time to time, you come across articles on WordPress on the Internet, where people share snippets and tips (including on our website) that you add to your theme’s functions.php file. These snippets are not so big to draw them into a full-fledged plugin, but some of them are certainly wonderful and add some functionality to the site, and they are not dependent on the template used, for example, redirecting users to random entries.

In such cases, you will need a plugin for the entire site (site-specific), which will act as well as the functions.php file, but at the same time allows you to save the buns that you have already got used to when you change themes.

Why Do You Need This Plugin

As already mentioned, it will allow you to save key “add-ons” to your site that you have already found and implemented. This can be, for example How to redirect users to a random post and other independent functions that are not directly dependent on the template.

The above functions are what you need in case you decide to change the template, and even if you do not decide. Can you imagine turning off a template and losing all of your shortcodes? It will be a nightmare!🙂

When using the site-specific plug-in, you will get unkillable in terms of site functionality. If suddenly you insert a newly-found snippet with incorrect formatting, instead of the white screen of death WordPress, you will receive only a warning from the plugin manager that it detected an error and disable the plugin. Of course, it will “break” your site a little for a few seconds, but you can immediately remove the “bad” code, and the site will return to normal.

This is how to choose the lesser of two evils: either you will be kicked out of the admin panel and break the site (due to the wrong code in functions.php), or else you will break the site, but in a couple of seconds you will restore it.

How To Make Such A Plugin For Your Site?

Probably, it seems that it is very difficult? Nope

  • All that is needed is to create a new folder in the plugins directory. For example: / wp-content / plugins / techtodu-plugin /
  • Open an empty file and save it as “techtodu-plugin.php”
  • Paste the code below into this file:
    1 <?php
    2 /*
    3 Plugin Name: Site Plugin for techtodu.com
    4 Description: Site specific code changes for techtodu.com
    5 */
    6 /* We start adding functions under this comment. */
    7
    8
    9 /* Stop adding features to this comment. */
    10 ?>
  • Now upload this file to the created folder in the plugins directory on the server, and then activate the plugin through the admin area

Based on the foregoing, I recommend adding correct snippets, which you can find on our website in this plugin, rather than in functions.php.
I hope this method will become a new trend. And believe me, he will save you a lot of time when changing topics.

Facebook Twitter LinkedIn Telegram Pocket

Related Posts:

Are you looking for a way to add a support / documentation section on your site? Want to find out the best way to add a wiki knowledge base to your WordPress site? In today’s article, we will show you how to create a wiki knowledge base in WordPress without pl...
Would you like to add a WordPress widget to your site’s header area? Widgets allow you to easily add content blocks to specific places in your theme. In today’s article, we will show you how easy it is to add a WordPress widget to the site header. Why And Wh...
The developers of the popular AMP plugin for WordPress – AMP for WP – have released a patch for a critical vulnerability discovered last month. While the work was underway to eliminate the vulnerability, the plugin was removed from the corresponding section on...