{"id":133167,"date":"2014-10-21T10:30:00","date_gmt":"2014-10-21T14:30:00","guid":{"rendered":"http:\/\/premium.wpmudev.org\/blog\/?p=133167"},"modified":"2022-03-02T04:41:26","modified_gmt":"2022-03-02T04:41:26","slug":"why-you-shouldnt-use-functions-php","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/why-you-shouldnt-use-functions-php\/","title":{"rendered":"Why You Shouldn\u2019t Use functions.php (And What You Should Do Instead)"},"content":{"rendered":"<p>Have you come across WordPress tutorials asking you to add code to your <em>functions.php<\/em> file to get something done? <strong>Don&#8217;t do it!<\/strong> Read below and find out why&#8230;<\/p>\n<p>In this article, I will explain why you shouldn&#8217;t add code to your <em>functions.php<\/em> file, and offer you some far better alternatives:<\/p>\n<ul>\n<li><a href=\"#threebroadcamps\">Three Broad Camps<\/a><\/li>\n<li><a href=\"#howwordpressworks\">How WordPress Works<\/a><\/li>\n<li><a href=\"#phpvsfunctions\">PHP vs. functions.php<\/a><\/li>\n<li><a href=\"#wheredoesfunctionsfitin\">Where Does functions.php Fit In?<\/a><\/li>\n<li><a href=\"#whenyoushouldntuse\"><em>When<\/em> You Shouldn&#8217;t Use functions.php<\/a><\/li>\n<li><a href=\"#whyyoushouldntuse\"><em>Why<\/em> You Shouldn&#8217;t Use functions.php<\/a><\/li>\n<li><a href=\"#whattodoinstead\">What To Do Instead<\/a>\n<ul>\n<li><a href=\"#childthemefunctions\">Use Child Theme functions.php<\/a><\/li>\n<li><a href=\"#plugin\">Use A WordPress Plugin For Functions.php<\/a><\/li>\n<li><a href=\"#yourownplugin\">Create Your Own Plugin<\/a><\/li>\n<li><a href=\"#mu-plugin\">Going a Step Further: Creating a \u201cMust Use\u201d Plugin (MU-Plugin)<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#putfunback\">Let\u2019s Put the Fun Back Into functions.php<\/a><\/li>\n<\/ul>\n<h2 id=\"threebroadcamps\">Three Broad Camps<\/h2>\n<p>I believe people who use WordPress can be separated into three broad camps:<\/p>\n<ol>\n<li><strong>Plug and players:<\/strong>\u00a0WordPress enthusiasts who are probably not experienced website designers and are looking for a turnkey solution. They will find a theme, install it, and probably get on with content creation.<\/li>\n<li><strong>Tweakers:<\/strong>\u00a0These folks\u00a0will take a theme that could probably be used straight out of the box and apply their own tweaks.\u00a0They will probably use the <em>custom.css<\/em> and <em>custom_functions.php<\/em> files (or similar) to customize their\u00a0theme. They will take an off the shelf option and mess around with it until they have something that (a) suits their needs, and (b) looks unique.<\/li>\n<li><strong>Frameworkers:<\/strong> These are usually developers who\u00a0will start off with a theme framework that offers very little beyond \u2013 you guessed it \u2013 a framework, upon which content can sit. Hours or days later, they will have crafted something truly unique and customized to their \u2013 or their client&#8217;s specific needs.<\/li>\n<\/ol>\n<p>If I had to guess, I would say the\u00a0biggest camp out of the three is the <em>tweakers<\/em>.<\/p>\n<p>And let&#8217;s face it: <strong>WordPress is a tweaker&#8217;s paradise<\/strong>. Armed with nothing more than Google search and your <a title=\"Functions File Explained (WordPress Codex)\" href=\"http:\/\/codex.wordpress.org\/Functions_File_Explained\" rel=\"noopener\" target=\"_blank\"><em>functions.php<\/em><\/a> file, WordPress makes it easy to<a title=\"Eight Useful Code Snippets for WordPress\" href=\"http:\/\/www.elegantthemes.com\/blog\/tips-tricks\/eight-useful-code-snippets-for-wordpress\" rel=\"noopener\" target=\"_blank\">\u00a0add diverse functionality to your website with relative ease<\/a>.<\/p>\n<p>The only problem is many tweakers are playing with fire. Using <em>functions.php<\/em> to add functionality to your site can be an accident waiting to happen (for multiple reasons).<\/p>\n<figure class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"attachment-600x600\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2019\/10\/functions-php-2019.png\" alt=\"functions.php file\" width=\"600\" height=\"377\" \/><figcaption class=\"wp-caption-text\">Add functionality to your WordPress site, but not with your functions.php file.<\/figcaption><\/figure>\n<h2 id=\"howwordpressworks\">How WordPress Works<\/h2>\n<p>At the core of WordPress lies a simple\u00a0principle: design and functionality should (whenever possible) be clearly separated.<\/p>\n<p>That is why we have themes\u00a0and plugins; ostensibly, themes are solely responsible for design and plugins are solely responsible for functionality. One should be able to switch themes without affecting functionality, and one should be able to deactivate plugins without affecting the design.<\/p>\n<p>This isn&#8217;t\u00a0<em>always\u00a0<\/em>possible (some of the reasons for which I&#8217;ll get onto shortly), but the separation of design and functionality\u00a0is an ideal that any WordPress developer worth his or her salt should aim for.<\/p>\n<h2 id=\"phpvsfunctions\">PHP vs functions.php<\/h2>\n<p>WordPress beginners often get confused and ask questions like:<\/p>\n<ul>\n<li>Where is the functions PHP in WordPress?<\/li>\n<li>What does PHP do in WordPress?<\/li>\n<li>How do I add a function to a PHP function in WordPress?<\/li>\n<li>Is the functions PHP file required in each theme?<\/li>\n<\/ul>\n<p>First off, PHP is found everywhere in WordPress, as it&#8217;s the main language WordPress is built on. We&#8217;re not covering what PHP does in WordPress in this post, but you can read all about it in our\u00a0<a href=\"https:\/\/wpmudev.com\/blog\/wordpress-development-beginners-php\/\" target=\"_blank\" rel=\"noopener\">Learn PHP tutorial series for WordPress development beginners<\/a>.<\/p>\n<p><em>functions.php<\/em> is a\u00a0theme-specific file, by which I mean it exists in a WordPress theme&#8217;s directory and pertains only to that theme. Every theme should have a <em>functions.php<\/em> file located inside the theme folder.<\/p>\n<figure class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"attachment-670x670\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2019\/10\/theme-functions-php.png\" alt=\"Theme Functions PHP File inside Theme directory\" width=\"600\" height=\"575\" \/><figcaption class=\"wp-caption-text\">A functions.php file is required for each WordPress theme and can be found inside the theme directory.<\/figcaption><\/figure>\n<p style=\"text-align: left;\">You can learn more about the functions.php file, what it does, and how to add functions in our <a href=\"https:\/\/wpmudev.com\/blog\/functions-file\/\" target=\"_blank\" rel=\"noopener\">ultimate guide to the WordPress functions.php file<\/a>.<\/p>\n<h2 id=\"wheredoesfunctionsfitin\">So Where Does functions.php Fit Into This?<\/h2>\n<p>As you might guess from the name, <em>functions.php<\/em> contains functions that are relevant to the theme, examples of which are:<\/p>\n<ul>\n<li>Use of featured images<\/li>\n<li>Length of excerpts<\/li>\n<li>Widgetized areas<\/li>\n<\/ul>\n<p>These types of functions are\u00a0exceptions that prove WordPress&#8217;\u00a0design\/functionality separation rule. While they\u00a0<em>are<\/em> elements of functionality, they are relevant only to their parent theme, and\u00a0may not be appropriate when applied to another theme. As such, they\u00a0belong in <em>functions.php<\/em> and should remain there.<\/p>\n<p>For example, an excerpt length of 200 words might look fantastic on one theme but\u00a0terrible on another. Although we are technically playing\u00a0around with the &#8220;functionality&#8221; of a site by adjusting the excerpt length,\u00a0including the necessary code in <em>functions.php<\/em> is the right thing to do.<\/p>\n<p>I don&#8217;t intend to get into the complexities of\u00a0effectively utilizing <em>functions.php<\/em> in this article, but it is worth mentioning at this time that if you&#8217;re going to include a lot of theme-specific functionality in your site, you should consider\u00a0creating an <em>inc<\/em> directory within your theme (or using a pre-existing directory if it already exists) to\u00a0effect some organization amongst your theme&#8217;s functions. <a title=\"Functions.php vs Plugin, Who Wins?\" href=\"https:\/\/tommcfarlin.com\/functions-php-vs-plugin-who-wins\/\" rel=\"noopener\" target=\"_blank\">Here&#8217;s a great read from WordPress developer Tom McFarlin<\/a> on the subject if you want to\u00a0go further down that path.<\/p>\n<p>My ultimate point is this: <strong><em>functions.php<\/em> is not the enemy<\/strong>. It is a valuable cog in a theme&#8217;s engine; necessary for all but the most basic of designs.<\/p>\n<p>However, the misuse of <em>functions.php<\/em> is rife and should be stopped.<\/p>\n<h2 id=\"whenyoushouldntuse\"><em>When<\/em>\u00a0You Shouldn&#8217;t Use functions.php<\/h2>\n<p>The simple answer to when you should use <em>functions.php<\/em>\u00a0is &#8220;almost never.&#8221;<\/p>\n<p>The slightly more complicated answer is &#8220;use your noggin.&#8221;<\/p>\n<p>If you understand what <em>functions.php<\/em> is for (functionality strictly related to a particular theme), you should be able to figure out what it\u00a0<em>isn&#8217;t <\/em>for.<\/p>\n<p>Easy examples can be found within your WordPress website&#8217;s plugins directory. Plugins are (ideally speaking) logically arranged &#8220;packets&#8221; of code\u00a0separated by their intended functionality.<\/p>\n<p>One of the best (and higher\u00a0profile) examples of the whole point of\u00a0separating functionality from design in WordPress is <a href=\"http:\/\/www.google.com\/analytics\/\" rel=\"noopener\" target=\"_blank\">Google Analytics<\/a>\u00a0tracking code, which looks\u00a0like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"attachment-600x600 aligncenter\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2019\/10\/google-analytics-code.png\" alt=\"Google Analytics Tracking Code\" width=\"600\" height=\"193\" \/><\/p>\n<p style=\"text-align: center;\">This code needs to be added into the <em>head<\/em>\u00a0section of your site in order for visits to be tracked.<\/p>\n<p>You have\u00a0three main options when it comes to adding this code:<\/p>\n<ol>\n<li>Add it manually to your theme&#8217;s <em>header.php<\/em> file<\/li>\n<li>Add it manually to your <em>functions.php<\/em>\u00a0(using a <a title=\"WordPress Hooks\" href=\"http:\/\/codex.wordpress.org\/Plugin_API#Hook_to_WordPress\" rel=\"noopener\" target=\"_blank\">hook<\/a>)<\/li>\n<li>Use a plugin<\/li>\n<\/ol>\n<p>If you use options one or two, your tracking code will disappear if you change themes and visitors will no longer be counted by Google. (It may also disappear the next time your theme is updated.) But if you use option three, you&#8217;re golden.\u00a0Unless you have a senior moment and deactivate the plugin you&#8217;re using, that tracking code is going nowhere.<\/p>\n<p>My simple advice is this: <strong>If in doubt, use a plugin<\/strong>. They&#8217;re popular for a reason. <a href=\"https:\/\/wpmudev.com\/blog\/data-analytic-tools-wordpress\/\" target=\"_blank\" rel=\"noopener\">Check out these analytics plugins<\/a>.<\/p>\n<h2 id=\"whyyoushouldntuse\"><em>Why<\/em> You Shouldn&#8217;t Use functions.php<\/h2>\n<p>In explaining the &#8220;when&#8221; above, I have also gone a fair way in explaining the &#8220;why:&#8221; <strong>Don&#8217;t use <em>functions.php<\/em> because changing your theme will change the functionality of your site, which is all kinds of wrong<\/strong>.<\/p>\n<p>However, there are\u00a0a couple of other major points I should make to further strengthen the reasons for avoiding <em>functions.php<\/em> as much as possible.<\/p>\n<p>First of all, there is the dreaded &#8220;white screen of death.&#8221; Quite frankly, if you&#8217;ve never encountered this while messing around with WordPress, you haven&#8217;t lived. Or at least you were far more careful than me when you first started tinkering with WordPress.<\/p>\n<p>I feel at this stage we need a screenshot to clarify what this white screen of death actually looks like:<\/p>\n<figure class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"attachment-600x600\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2019\/10\/white-screen-of-death.jpg\" alt=\"WordPress White Screen Of Death\" width=\"600\" height=\"400\" \/><figcaption class=\"wp-caption-text\">Yep&#8230; the WordPress &#8216;White Screen of Death&#8217; displays a completely blank screen.<\/figcaption><\/figure>\n<p>Scary. But what does it\u00a0mean?<\/p>\n<p>Well, to put it in the Queen&#8217;s English, one encounters the white screen of death when one cocks up one&#8217;s PHP.<\/p>\n<p>In other words, you&#8217;ve screwed up.<\/p>\n<p>To put it another way, syntax errors in\u00a0PHP code inserted into <em>functions.php<\/em> can &#8220;break&#8221; your site, leading to you seeing nothing more than a white screen. (Don&#8217;t ask me where the &#8220;death&#8221; comes into it. As far as I&#8217;m aware, nobody gets hurt.)<\/p>\n<p>Upon\u00a0encountering the white screen of death, it&#8217;s better if you were\u00a0editing your site via <a href=\"http:\/\/codex.wordpress.org\/FTP_Clients\" rel=\"noopener\" target=\"_blank\">FTP<\/a> or an online IDE (like <a href=\"https:\/\/shiftedit.net\/\" rel=\"noopener\" target=\"_blank\">ShiftEdit<\/a>) rather than the WordPress backend, otherwise, you&#8217;ll have some trouble getting back into your site. Plus, you&#8217;ll get a slap on the wrist from me for using the WordPress backend. Naughty.<\/p>\n<p>But I digress. The point I&#8217;m getting to is this:\u00a0<strong>placing your PHP code into a plugin can prevent\u00a0the white screen of death from ever happening<\/strong>.\u00a0Instead, WordPress may be able to deactivate the offending plugin without negatively affecting the continuing operation of the site as a whole.<\/p>\n<p>Secondly, using <em>functions.php<\/em> is just plain messy if you plan on inserting more than a handful of code; especially if the theme you&#8217;re using already has existing functions.<\/p>\n<p>Thirdly, and as I have already mentioned above, code in <em>functions.php<\/em> is theme-specific (i.e. will not travel when you change themes) and\u00a0can be overwritten by theme updates.<\/p>\n<p>None of this is good and should convince you that <em>functions.php<\/em> is not the place you want to place your code in the majority of cases. Sure; leave whatever&#8217;s there by default as it is (on the assumption that the theme developer has included theme-specific functionality only), but any new code you&#8217;re adding is likely fair game.<\/p>\n<p>So what do you do instead?<\/p>\n<h2 id=\"whattodoinstead\">What To Do Instead<\/h2>\n<p>Well, as it turns out, you have 3 options:<\/p>\n<ol>\n<li>Add it to the <em>functions.php<\/em> of a <em>child theme<\/em><\/li>\n<li>Use a WordPress Custom Functions plugin<\/li>\n<li>Create your own plugin<\/li>\n<\/ol>\n<p>Let&#8217;s take a brief look at each of these options:<\/p>\n<h3 id=\"childthemefunctions\">Use Child Theme functions.php<\/h3>\n<p>You should <a href=\"https:\/\/wpmudev.com\/blog\/how-to-create-wordpress-child-theme\/\" target=\"_blank\" rel=\"noopener\">always use child themes with WordPress<\/a>. Especially if you plan to make any changes to your theme. This way, you won&#8217;t lose any custom design or modifications when the main (i.e. parent) theme of your site gets updated.<\/p>\n<p>If you want to <a href=\"https:\/\/wpmudev.com\/blog\/understanding-how-wordpress-outputs-code-from-child-themes\/\" target=\"_blank\" rel=\"noopener\">pull in styling from your parent theme to your child theme<\/a>, for example, you will have to enqueue it in your child theme\u2019s\u00a0<em>functions.php<\/em>\u00a0file. If your child theme doesn&#8217;t have one, you will need to <a href=\"https:\/\/wpmudev.com\/blog\/functions-file\/\" target=\"_blank\" rel=\"noopener\">create\u00a0a functions.php file<\/a> for it.<\/p>\n<figure class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"attachment-670x670\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2019\/10\/child-theme-functions-php.png\" alt=\"Child Theme functions.php\" width=\"600\" height=\"420\" \/><figcaption class=\"wp-caption-text\">If you must use the rod, don&#8217;t spare the child theme functions.php<\/figcaption><\/figure>\n<p>If you need to add code to the <em>functions.php<\/em> file, do it\u00a0in your child theme&#8217;s <em>functions.php<\/em>.<\/p>\n<p>Note, however, that this is not the recommended solution and it can lead to errors.\u00a0There is a better alternative&#8230; use a plugin!<\/p>\n<h3 id=\"plugin\">Use A WordPress Plugin For Functions.php<\/h3>\n<p>A better option than adding code directly to the functions.php file is to use a WordPress custom functions plugin.<\/p>\n<figure class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"attachment-670x670\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2019\/10\/my-custom-functions-plugin.png\" alt=\"My Custom Functions WordPress Plugin\" width=\"600\" height=\"275\" \/><figcaption class=\"wp-caption-text\">My Custom Functions WordPress Plugin<\/figcaption><\/figure>\n<p><a href=\"https:\/\/wordpress.org\/plugins\/my-custom-functions\/\" rel=\"noopener\" target=\"_blank\">My Custom Functions<\/a> is a nifty free WordPress functionality plugin that lets you\u00a0easily add custom PHP code to your WordPress website without editing the <em>functions.php<\/em> file of your theme or any of your plugin files.<\/p>\n<p>To install the plugin, go to <strong>Plugins &gt; Add New<\/strong> in your dashboard menu, type in &#8220;my custom functions&#8221; into the keyword search field, locate the &#8216;My Custom Functions&#8217; plugin by Space X-Chimp, and click on <strong>Install Now<\/strong>, then <strong>Activate<\/strong>&#8230;<\/p>\n<figure class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"attachment-670x670\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2019\/10\/my-custom-functions-add-plugin-1.png\" alt=\"Add My Custom Functions WordPress Plugin\" width=\"600\" height=\"301\" \/><figcaption class=\"wp-caption-text\">Install and activate My Custom Functions WordPress plugin.<\/figcaption><\/figure>\n<p>Once the plugin has been activated a new menu item appears in the WordPress Settings menu. To add custom functions to WordPress, select <strong>PHP Inserter<\/strong> from the Settings menu.<\/p>\n<figure class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"attachment-670x670\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2100\/10\/my-custom-functions-menu-1.png\" alt=\"My Custom Functions WordPress menu\" width=\"600\" height=\"267\" \/><figcaption class=\"wp-caption-text\">My Custom Functions WordPress menu<\/figcaption><\/figure>\n<p>This brings up the\u00a0My Custom Functions screen.\u00a0Just add your custom PHP code into the field, click Save and turn the function ON and the plugin will automatically add your PHP code to your website without changing any of your theme files and without slowing down your website.<\/p>\n<p style=\"text-align: left;\"><figure class=\"wp-caption center\" data-caption=\"true\"><video loop muted autoplay playsinline class='dev-html5-video'><source src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2019\/10\/my-custom-functions.webm\" type=\"video\/webm\"><source src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2019\/10\/my-custom-functions.mp4\" type=\"video\/mp4\"><\/video><figcaption class=\"wp-caption-text\">Add custom functions to WordPress with My Custom Functions plugin.<\/figcaption><\/figure><\/p>\n<p>This plugin works independently of the theme you have installed, so you can use it with any theme, even if the theme does not have a <em>functions.php<\/em> file.<\/p>\n<p>The benefit of using this method is that any code you add to your WordPress site using this plugin will remain unaffected if you edit the content of the theme\u2019s <em>functions.php<\/em> file, or even if you change your theme. This also works for plugins, so your custom PHP code won&#8217;t be overwritten even if you update or switch themes or plugins.<\/p>\n<p>There is one more option for adding code to your WordPress site without touching your theme&#8217;s\u00a0<em>functions.php<\/em> file.<\/p>\n<h3 id=\"yourownplugin\">Create Your Own Plugin<\/h3>\n<p>If you&#8217;re a garden variety WordPress tweaker and have never created your own plugin before,\u00a0you&#8217;d be forgiven for thinking that it involves\u00a0some kind of complicated and arcane process. Perhaps some kind of\u00a0incantation is required.<\/p>\n<p>Fortunately, that&#8217;s not the case. If you know how to edit a <em>functions.php<\/em> file properly (via FTP or an online IDE), you already have the necessary skills to create a plugin for all of the\u00a0code you would otherwise be putting into <em>functions.php.<\/em><\/p>\n<p>So let&#8217;s do it.<\/p>\n<p>Firstly, navigate to your WordPress website&#8217;s root folder via FTP (or your hosting panel&#8217;s file manager, or via an online IDE). From there, you should navigate to <em>wp-content\/plugins<\/em>:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"attachment-670x670 aligncenter\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2100\/10\/wordpress-directory.png\" alt=\"WordPress directory folders\" width=\"600\" height=\"359\" \/><\/p>\n<p style=\"text-align: center;\">WordPress directory folders<\/p>\n<p>The folders you see within the plugins directory are\u00a0(as you may\u00a0imagine) the plugins currently installed on your site. To create your own plugin, just create a new folder. I&#8217;m going to name it <em>tme-custom-functions<\/em>:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"attachment-670x670 aligncenter\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2100\/10\/tme-custom-functions-1.png\" alt=\"WordPress custom functions plugin folder\" width=\"600\" height=\"98\" \/><\/p>\n<p style=\"text-align: center;\">WordPress custom functions plugin folder<\/p>\n<p>(&#8220;TME&#8221; are my initials, and I&#8217;m prepending them to the plugin name so that I don&#8217;t accidentally use an existing plugin&#8217;s name.)<\/p>\n<p>Next, create a PHP file with the same name within your plugin&#8217;s folder:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"attachment-670x670 aligncenter\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2100\/10\/tme-custom-functions-2.png\" alt=\"WordPress plugin add to functions.php\" width=\"600\" height=\"138\" \/><\/p>\n<p style=\"text-align: center;\">Use this WordPress custom functions plugin to add code to <em>functions.php<\/em><\/p>\n<p>Finally, insert the following code into your brand new PHP file:<\/p>\n<pre>&lt;?php\r\n\r\n\/**\r\n* Plugin Name: Custom Functions Plugin\r\n* Description: This plugin contains all of my awesome custom functions.\r\n* Author: Tom Ewer\r\n* Version: 0.1\r\n*\/\r\n\r\n\/* Your code goes below here. *\/\r\n\r\n\/* Your code goes above here. *\/\r\n\r\n?&gt;\r\n<\/pre>\n<p>That&#8217;s all there is to it! Make sure your file is saved and your new WordPress custom functions plugin will now appear in your WordPress plugins\u00a0list:<\/p>\n<figure class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"attachment-670x670\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2100\/10\/wordpress-plugins-table.png\" alt=\"WordPress plugins table\" width=\"600\" height=\"239\" \/><figcaption class=\"wp-caption-text\">Your new WordPress custom functions plugin&#8230; ready to activate and use.<\/figcaption><\/figure>\n<p>Of course, your plugin doesn&#8217;t\u00a0<em>do\u00a0<\/em>anything yet, but you are now free to insert any custom functions that previously resided in your <em>functions.php<\/em> file, and they will continue to work as normal.<\/p>\n<h3 id=\"mu-plugin\">Going a Step Further: Creating a &#8220;Must Use&#8221; Plugin (MU-Plugin)<\/h3>\n<p>The average plugin is all well and good, but what if\u00a0you want your chosen functions to work on your site under all circumstances? What if you don&#8217;t want your new custom plugin cluttering up your plugins list?<\/p>\n<p>It sounds like you need to make it a &#8220;must use&#8221; plugin, which are plugins that are always active on your site (and cannot be deactivated). They won&#8217;t even appear on the plugins list in WordPress unless you click on the &#8216;Must-Use&#8217; link in the plugins table.<\/p>\n<p>To make your plugin &#8220;must use,&#8221; simply create a folder named <em>mu-plugins<\/em> within your WordPress site&#8217;s <em>wp-content<\/em> directory, then move your plugin&#8217;s PHP file (<em>not <\/em>the whole folder) into it.<\/p>\n<p>Hey, presto! The plugin disappears from your list and reappears within a new Must-Use section:<\/p>\n<figure class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"attachment-670x670\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2100\/10\/must-use-plugin.png\" alt=\"Must-use plugin\" width=\"600\" height=\"209\" \/><figcaption class=\"wp-caption-text\">Make your WordPress functions plugin a must-use plugin.<\/figcaption><\/figure>\n<h2 id=\"putfunback\">Let&#8217;s Put the Fun Back Into functions.php<\/h2>\n<p><span style=\"font-weight: 400;\">Hopefully, now you know what you should and shouldn\u2019t use the <\/span><i><span style=\"font-weight: 400;\">functions.php<\/span><\/i><span style=\"font-weight: 400;\"> file for and that there are better alternatives to add code to WordPress, like using a WordPress custom functions plugin, creating your own plugin, or even using your child theme <\/span><i><span style=\"font-weight: 400;\">functions.php<\/span><\/i><span style=\"font-weight: 400;\"> file.<\/span><\/p>\n<p>Creating your own plugin to add custom functions to WordPress is always an option. If nothing else, it can make you look like a brainy WordPress developer by creating a plugin that will appear on your clients&#8217; WordPress backend, or at least make you feel far\u00a0better at coding than you actually are (at least, that&#8217;s how it makes\u00a0<em>me <\/em>feel!)<\/p>\n<p>For more useful information on what you should know about using\u00a0<em>functions.php<\/em>,\u00a0 check out our\u00a0<a href=\"https:\/\/wpmudev.com\/blog\/functions-file\/\" target=\"_blank\" rel=\"noopener\">ultimate guide to the WordPress functions.php file<\/a>. Or, if you really want to impress the WordPress community, why not <a href=\"https:\/\/wpmudev.com\/blog\/wordpress-development-beginners-getting-started\/\" target=\"_blank\" rel=\"noopener\">learn PHP and start coding your own plugins and themes<\/a>? It&#8217;s fun, functional, and free!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you come across WordPress tutorials asking you to add code to your functions.php file to get something done? Don&#8217;t do it! Read below and find out why&#8230; In this article, I will explain why you shouldn&#8217;t add code to your functions.php file, and offer you some far better alternatives: Three Broad Camps How WordPress [&hellip;]<\/p>\n","protected":false},"author":37930,"featured_media":179781,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[263],"tags":[174,778],"tutorials_categories":[],"class_list":["post-133167","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-php","tag-functions"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/133167","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/37930"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=133167"}],"version-history":[{"count":12,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/133167\/revisions"}],"predecessor-version":[{"id":206603,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/133167\/revisions\/206603"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/179781"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=133167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=133167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=133167"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=133167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}