Advantages Of Saving Scripts In The Site-Custom Plugin

I remembered back then when I started blogging a few years ago (my first blog is a local gossip blog). I often made common mistakes made by rookies. One of it was saving my scripts in the functions.php. There are few times my site locked out due to faulty code. I went panicked and enraged and nearly wipe out my site.

Luckily, my hosting provider, SiteGround which is famous for their customer service helped me to fix my site each time I have a problem. Read my SiteGround review here.

So, then I decided that I need to move forward and I can't stay as novice forever. I started to create site-custom plugin for my site. And in this article, I want to share with you the advantages of saving scripts in the site-custom plugin instead of functions.php from my experience and viewpoint. You might want to read how to create a WordPress plugin from scratch or take a look at 5 basic security practices for your WordPress plugin.

Survivability

This is the biggest advantages of saving scripts in the site-custom plugin. I'm pretty sure you know that your scripts will not be preserved when you change to other themes. It may or may not be overwritten by current theme updates. If this happened, all your codes and hard work will be all for naught unless you saved a copy of it somewhere else.

By saving scripts in the site-custom plugin, you ensure that it will survive any updates of your current theme or if you change to other themes completely. Your scripts will also stay functional even after WordPress itself update with the exception there are no amendments by WordPress to any functions you currently use in your site-custom plugin.

For example, there are may or may not have any new introduction or depreciation of some WordPress filter or action you currently use after WordPress updates. In that case, always remember to check on WordPress change log after it released before you update your WordPress.

More Control, Easy To Handle

Have you ever locked out from your site without being able to access your admin page? Or have you ever experience White Screen of Death (commonly known as WSOD within WordPress community) or at least heard of it? I'm sure you have an idea how it looks when you are locked out of your site.

As for White Screen of Death, if you have never experience or heard about it, let's take a look at the images below. Please keep in mind that depending on the web browser, White Screen of Death may look slightly different.

Advantages Of Saving Scripts In The Site-Custom Plugin
Image 1 (Google Chrome).
Advantages Of Saving Scripts In The Site-Custom Plugin
Image 2 (Mozilla Firefox).

Scary, isn't it? Suddenly your website turns into plain white with nothing. For the experienced bloggers, these both are simply common errors. But for new bloggers, these may cause panic.

By saving your scripts in the site-custom plugin, you indirectly have a break-proof site. How does it work? Let say you trying to add unknown scripts from the internet using your built-in plugin editor. When you save your scripts and the built-in plugin editor detect that saved codes may break your site. It will automatically deactivate your site-custom plugin, thus preventing White Screen of Death from your site. Cool, right?

Aside from that, if in case of an emergency such as locked out from your site, you can use WP-CLI to manually deactivate your site-custom plugin. I agree you can also change the theme by activating other theme using WP-CLI to troubleshoot. But I personally wouldn't recommend it.

Imagine suddenly your website theme changed and widget or other things scattered around. It is definitely not good for the user experience of your visitors. I personally believe it's better to sacrifice a single plugin temporary rather than whole site or theme.

Distribution

If your dream is to contribute to the community or you simply want to sell your services. Then this is the advantages you will definitely love.

By saving scripts in the site-custom plugin, you can distribute it easily it to the public, your customers, or to specific people you want. You can simply distribute your plugin (.zip) files and your users can install it easily from their admin page. This is also a good way for you to start your brand.

Conclusion

I hope this article will give you an overview of the advantages of saving scripts in the site-custom plugin. If you still using functions.php to save your scripts, I believe it is time for you to switch to the site-custom plugin. It is definitely the best-practice that will save you time in the long-term.

Please don’t forget to check out how to create a WordPress plugin. If there any of the advantages I forgot to mention above, please let me know in the comments section.

  • If you think your friends would find this useful, please share it with them. It will allow us help more people.
  • To get more of our latest update, please subcribe to our newsletter.
  • You can also print this article for reference.
This article has been printed from https://www.jebatonline.com/articles/advantages-of-saving-scripts-in-the-site-custom-plugin/

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.