{"id":37708,"date":"2022-10-25T07:00:06","date_gmt":"2022-10-25T14:00:06","guid":{"rendered":"https:\/\/dhblog.dream.press\/blog\/?p=37708"},"modified":"2025-05-21T22:20:57","modified_gmt":"2025-05-22T05:20:57","slug":"guide-to-wp-functions","status":"publish","type":"post","link":"https:\/\/www-dev.dreamhost.com\/blog\/guide-to-wp-functions\/","title":{"rendered":"Everything You Need to Know About the WordPress functions.php File"},"content":{"rendered":"\n<p>To get involved in <a href=\"https:\/\/www.dreamhost.com\/blog\/learn-wordpress\/\" target=\"_blank\" rel=\"noopener\">WordPress development<\/a>, you\u2019ll first need to understand how the platform\u2019s most important files work. WordPress makes it pretty easy to tinker with your site. However, it can be difficult to know where to start \u2014 or predict what your changes will actually do.<\/p>\n\n\n\n<p>A perfect place to learn is the <a href=\"https:\/\/codex.wordpress.org\/Functions_File_Explained\" target=\"_blank\" rel=\"noopener\"><i>functions.php<\/i> file<\/a>, which is also known as the functions file. This is a common location for making changes and adding code to WordPress. By editing this file, you can accomplish several useful things, such as adding Google Analytics to your site, creating custom menus, or displaying a post\u2019s estimated reading time.<\/p>\n\n\n\n<h2 id=\"h-what-is-the-functions-php-file\" class=\"wp-block-heading\"><b>What Is the functions.php File?<\/b><\/h2>\n\n\n\n<p>The WordPress <i>functions.php<\/i> file comes with all free and premium WordPress themes. To the untrained eye, it may not look like much, but the functions file is a powerful tool that enables you to do a lot of interesting things:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"1024\" height=\"379\" data-src=\"https:\/\/www.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-theme-support-1024x379.jpg\" alt=\"WordPress functions.php\" class=\"wp-image-37723 lazyload\" data-srcset=\"https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-theme-support-1024x379.jpg 1024w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-theme-support-300x111.jpg 300w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-theme-support-768x284.jpg 768w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-theme-support-1536x569.jpg 1536w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-theme-support-600x222.jpg.webp 600w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-theme-support-750x278.jpg.webp 750w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-theme-support-100x37.jpg 100w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-theme-support.jpg.webp 1588w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/379;\" \/><\/figure><\/div>\n\n\n<p>The <a href=\"https:\/\/codex.wordpress.org\/Main_Page\" target=\"_blank\" rel=\"noopener\">WordPress Codex<\/a> describes the functions file like this:<\/p>\n\n\n\n<p>\u201cYou can use it to call functions, both PHP and built-in WordPress, and to define your own functions. You can produce the same results by adding code to a WordPress Plugin or through the WordPress Theme functions file.\u201d<\/p>\n\n\n\n<p>In simple terms, the functions file enables you to add custom code to your site. It lets you create new functions or reference existing ones in customized ways. As the Codex points out, this makes the functions file very similar to a plugin, but there are some differences between the two.<\/p>\n\n\n\n<p>The most important difference is that the functions file belongs to a specific theme. If you were to change themes or update to a newer version, the changes you\u2019ve made would disappear.<\/p>\n\n\n\n<p>For this reason, you should consider creating a <a href=\"https:\/\/www.dreamhost.com\/blog\/why-you-need-a-child-theme\/\" target=\"_blank\" rel=\"noopener\">child theme<\/a> and adding the new code to the child\u2019s functions file instead. This way, you can update the parent theme without losing your changes.<\/p>\n\n\n\n<p>Whether you choose to use the functions file or <a href=\"https:\/\/www.dreamhost.com\/blog\/writing-plugins-for-wordpress\/\" target=\"_blank\" rel=\"noopener\">create a plugin<\/a> is entirely up to you. For now, let\u2019s look at the different ways you can edit your functions file!<\/p>\n\n\n\n<h2 id=\"h-how-to-edit-the-functions-file-2-methods\" class=\"wp-block-heading\"><b>How to Edit the Functions File (2 Methods)<\/b><\/h2>\n\n\n\n<p>Editing your functions file is easy when using a standard text editor, like TextEdit or Notepad. However, before you get started, it is vitally important that you <a href=\"https:\/\/www.dreamhost.com\/blog\/how-to-back-up-wordpress-tutorial\/\" target=\"_blank\" rel=\"noopener\">create a backup<\/a> of your site and save the original, unedited <i>functions.php<\/i> file. This will enable you to restore your website if something goes wrong during the editing process.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-1-use-the-wordpress-editor\"><b>1. Use the WordPress Editor<\/b><\/h3>\n\n\n\n<p>If you have access to the WordPress admin interface, you can edit the functions file directly from the Theme Editor. Go to <i>Appearance &gt; Editor<\/i>:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"1024\" height=\"474\" data-src=\"https:\/\/www.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-theme-editor-stylesheet-css-1024x474.jpg\" alt=\"WordPress Theme File Editor\" class=\"wp-image-37724 lazyload\" data-srcset=\"https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-theme-editor-stylesheet-css-1024x474.jpg 1024w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-theme-editor-stylesheet-css-300x139.jpg 300w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-theme-editor-stylesheet-css-768x356.jpg 768w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-theme-editor-stylesheet-css-1536x712.jpg 1536w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-theme-editor-stylesheet-css-600x278.jpg.webp 600w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-theme-editor-stylesheet-css-750x347.jpg.webp 750w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-theme-editor-stylesheet-css-100x46.jpg 100w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-theme-editor-stylesheet-css.jpg.webp 1999w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/474;\" \/><\/figure><\/div>\n\n\n<p>On the right-hand side of the screen, you will see a list of all your theme files. These differ depending on which theme you use, but one of the options should be <i>Theme Functions<\/i> (<i>functions.php<\/i>).<\/p>\n\n\n\n<p>Simply click on the file to open it in the editor:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"1024\" height=\"452\" data-src=\"https:\/\/www.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-theme-functions-functions-php-file-1024x452.jpg\" alt=\"WordPress Theme Editor functions.php file\" class=\"wp-image-37725 lazyload\" data-srcset=\"https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-theme-functions-functions-php-file-1024x452.jpg 1024w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-theme-functions-functions-php-file-300x133.jpg 300w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-theme-functions-functions-php-file-768x339.jpg 768w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-theme-functions-functions-php-file-1536x678.jpg 1536w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-theme-functions-functions-php-file-600x265.jpg.webp 600w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-theme-functions-functions-php-file-750x331.jpg.webp 750w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-theme-functions-functions-php-file-100x44.jpg 100w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-theme-functions-functions-php-file.jpg.webp 1938w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/452;\" \/><\/figure><\/div>\n\n\n<p>Now, you can edit the file directly. Don\u2019t forget to click on <i>Update File<\/i> at the bottom to save your changes when you\u2019re done.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-2-access-the-file-through-ftp\"><b>2. Access the File Through FTP<\/b><\/h3>\n\n\n\n<p>If you are unable to use the admin dashboard or prefer to configure files directly, you can also access the functions file using a <a href=\"https:\/\/www.dreamhost.com\/blog\/ftp-sftp-guide-for-wordpress-users\/\" target=\"_blank\" rel=\"noopener\">Secure File Transfer Protocol (SFTP) client <\/a>such as <a href=\"https:\/\/filezilla-project.org\/\" target=\"_blank\" rel=\"noopener\">FileZilla<\/a>.<\/p>\n\n\n\n<p>Open your FTP tool and enter your hosting credentials to connect to your site. To find the right file, navigate to <i>wp-content\/themes\/[the name of your theme]<\/i>. When you open this folder, you\u2019ll see the <i>functions.php<\/i> file:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"1024\" height=\"477\" data-src=\"https:\/\/www.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-php-file-ftp-client-1024x477.jpg\" alt=\"editing the WordPress functions.php file through an FTP client\" class=\"wp-image-37722 lazyload\" data-srcset=\"https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-php-file-ftp-client-1024x477.jpg 1024w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-php-file-ftp-client-300x140.jpg 300w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-php-file-ftp-client-768x358.jpg 768w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-php-file-ftp-client-1536x716.jpg 1536w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-php-file-ftp-client-600x280.jpg.webp 600w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-php-file-ftp-client-750x350.jpg.webp 750w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-php-file-ftp-client-100x47.jpg 100w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-php-file-ftp-client.jpg.webp 1999w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/477;\" \/><\/figure><\/div>\n\n\n<p>All you have to do now is to edit it using your preferred text editing software. When you\u2019re done, save the file and overwrite it with the exact same name and extension.<\/p>\n\n\n\n<h2 id=\"h-8-tricks-you-can-accomplish-with-the-wordpress-functions-file\" class=\"wp-block-heading\"><b>8 Tricks You Can Accomplish With the WordPress Functions File<\/b><\/h2>\n\n\n\n<p>You should now be ready to start editing your functions file. To get you started, we\u2019ll look at some changes that you can make. All you need to do is copy the provided code snippets and paste them on a new line at the very bottom of your functions file (don\u2019t forget to save it!).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-1-add-google-analytics-to-your-site\"><b>1. Add Google Analytics to Your Site<\/b><\/h3>\n\n\n\n<p>There are several ways of integrating <a href=\"https:\/\/analytics.google.com\/\" target=\"_blank\" rel=\"noopener\">Google Analytics<\/a> with your WordPress site. One of them is by adding your credentials directly to the functions file. This method will insert the tracking code into your site\u2019s header, ensuring that every visit is properly recorded.<\/p>\n\n\n\n<p>Start by pasting <a href=\"https:\/\/www.dreamhost.com\/blog\/use-google-analytics-wordpress\/\" target=\"_blank\" rel=\"noopener\">the following code<\/a> at the bottom of your functions file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;?php\n\nadd_action('wp_head', 'wpb_add_googleanalytics');\n\nfunction wpb_add_googleanalytics() { ?&gt;\n\n\/\/ Replace this line with your Google Analytics Tracking ID\n\n&lt;?php } ?&gt;<\/pre>\n\n\n\n<p>All you have to do now is to <a href=\"https:\/\/support.google.com\/analytics\/answer\/1008080#trackingID\" target=\"_blank\" rel=\"noopener\">find your Tracking ID<\/a> and paste it into the line that contains the placeholder text. When you save the functions file, your site will be connected to your Google Analytics account.<\/p>\n\n\n\n<div class=\"article-newsletter article-newsletter--gradient\">\n\n\n<h2>Get Content Delivered Straight to Your Inbox<\/h2><p>Subscribe now to receive all the latest updates, delivered directly to your inbox.<\/p><form class=\"nwsl-form\" id=\"newsletter_block_\" novalidate><div class=\"messages\"><\/div><div class=\"form-group\"><label for=\"input_newsletter_block_\"><input type=\"email\"name=\"email\"id=\"input_newsletter_block_\"placeholder=\"Enter your email address\"novalidatedisabled=\"disabled\"\/><\/label><button type=\"submit\"class=\"btn btn--brand\"disabled=\"disabled\"><span>Sign Me Up!<\/span><svg width=\"21\" height=\"14\" viewBox=\"0 0 21 14\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n<path d=\"M13.8523 0.42524L12.9323 1.34521C12.7095 1.56801 12.7132 1.9304 12.9404 2.14865L16.7241 5.7823H0.5625C0.251859 5.7823 0 6.03416 0 6.3448V7.6573C0 7.96794 0.251859 8.2198 0.5625 8.2198H16.7241L12.9405 11.8535C12.7132 12.0717 12.7095 12.4341 12.9323 12.6569L13.8523 13.5769C14.072 13.7965 14.4281 13.7965 14.6478 13.5769L20.8259 7.39879C21.0456 7.17913 21.0456 6.82298 20.8259 6.60327L14.6477 0.42524C14.4281 0.205584 14.0719 0.205584 13.8523 0.42524Z\" fill=\"white\"\/>\n<\/svg>\n<\/button><\/div><\/form><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-2-change-the-default-login-error-message\"><b>2. Change the Default Login Error Message<\/b><\/h3>\n\n\n\n<p>By default, when somebody makes an unsuccessful login attempt to a WordPress site, they\u2019ll see an error message like this:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"1024\" height=\"792\" data-src=\"https:\/\/www.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-default-login-error-message-1024x792.jpg\" alt=\"WordPress default login error message\" class=\"wp-image-37715 lazyload\" data-srcset=\"https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-default-login-error-message-1024x792.jpg 1024w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-default-login-error-message-300x232.jpg 300w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-default-login-error-message-768x594.jpg 768w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-default-login-error-message-600x464.jpg.webp 600w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-default-login-error-message-750x580.jpg.webp 750w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-default-login-error-message-100x77.jpg 100w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-default-login-error-message.jpg.webp 1318w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/792;\" \/><\/figure><\/div>\n\n\n<p>Unfortunately, this message is giving potential intruders information about why the attempt didn\u2019t work. A more secure solution is to change this to a generic message instead.<\/p>\n\n\n\n<p>You can do this easily by adding the <a href=\"https:\/\/gist.github.com\/reviewsquirrel\/6bed41b280fdff5db75d18f0aac2cd79\" target=\"_blank\" rel=\"noopener\">following code<\/a> to your functions file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">function no_wordpress_errors(){\nreturn 'Something went wrong!';\n}\nadd_filter( 'login_errors', 'no_wordpress_errors' );<\/pre>\n\n\n\n<p>See that <i>Something went wrong!<\/i> message on the second line? That message will now appear the next time an incorrect login attempt occurs:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"1024\" height=\"711\" data-src=\"https:\/\/www.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-change-default-login-error-message-1024x711.jpg\" alt=\"WordPress custom login error message\" class=\"wp-image-37717 lazyload\" data-srcset=\"https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-change-default-login-error-message-1024x711.jpg 1024w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-change-default-login-error-message-300x208.jpg 300w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-change-default-login-error-message-768x533.jpg 768w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-change-default-login-error-message-600x417.jpg.webp 600w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-change-default-login-error-message-750x521.jpg.webp 750w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-change-default-login-error-message-100x69.jpg 100w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-change-default-login-error-message.jpg.webp 1308w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/711;\" \/><\/figure><\/div>\n\n\n<p>You can change the text to whatever you want, as long as you keep the single quote characters. Try it out with different messages to see how it works.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-3-add-the-estimated-reading-time-for-a-post\"><b>3. Add the Estimated Reading Time for a Post<\/b><\/h3>\n\n\n\n<p>This neat trick enables you to calculate and display the estimated amount of time required to read a post. Your visitors can then get a general idea of the content\u2019s length right away.<\/p>\n\n\n\n<p>To implement this code, you will need to make two separate edits. The first one happens within the <i>functions.php<\/i> file, where you\u2019ll want to paste <a href=\"https:\/\/birchtree.me\/blog\/reading-time-wp-php\/\" target=\"_blank\" rel=\"noopener\">the following snippet<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">function reading_time() {\n$content = get_post_field( 'post_content', $post-&gt;ID );\n$word_count = str_word_count( strip_tags( $content ) );\n$readingtime = ceil($word_count \/ 200);\nif ($readingtime == 1) {\n$timer = \" minute\";\n} else {\n$timer = \" minutes\";\n}\n$totalreadingtime = $readingtime . $timer;\nreturn $totalreadingtime;\n}<\/pre>\n\n\n\n<p>However, this snippet only performs the calculation. You\u2019ll now need to add the following code wherever you want the results to be displayed:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">echo reading_time();<\/pre>\n\n\n\n<p>For example, you could add it to the metadata that appears alongside each post. Every theme is constructed differently, but typically you\u2019ll find it in <i>template-parts &gt; post &gt; content.php<\/i>:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"978\" height=\"332\" data-src=\"https:\/\/www.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wp-functions-add-estimated-reading-time-for-wordpress-posts.jpg\" alt=\"WordPress functions.php estimated reading time\" class=\"wp-image-37726 lazyload\" data-srcset=\"https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wp-functions-add-estimated-reading-time-for-wordpress-posts.jpg.webp 978w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wp-functions-add-estimated-reading-time-for-wordpress-posts-300x102.jpg 300w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wp-functions-add-estimated-reading-time-for-wordpress-posts-768x261.jpg 768w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wp-functions-add-estimated-reading-time-for-wordpress-posts-600x204.jpg.webp 600w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wp-functions-add-estimated-reading-time-for-wordpress-posts-750x255.jpg.webp 750w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wp-functions-add-estimated-reading-time-for-wordpress-posts-100x34.jpg 100w\" data-sizes=\"(max-width: 978px) 100vw, 978px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 978px; --smush-placeholder-aspect-ratio: 978\/332;\" \/><\/figure><\/div>\n\n\n<p>The estimated reading time will now appear in each post\u2019s header alongside the date.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-4-remove-the-wordpress-version-number\"><b>4. Remove the WordPress Version Number<\/b><\/h3>\n\n\n\n<p>Old versions of WordPress may contain security flaws that malicious hackers and bots can exploit. One way to avoid this risk is to hide which version of WordPress your site uses. This is called <a href=\"https:\/\/en.wikipedia.org\/wiki\/Security_through_obscurity\" target=\"_blank\" rel=\"noopener\">security through obscurity<\/a>.<\/p>\n\n\n\n<p>Before we move on, it\u2019s important to note that obscurity should never be your <i>only<\/i> security measure. It\u2019s more like adding an extra bulwark to your already <a href=\"https:\/\/www.dreamhost.com\/blog\/secure-your-wordpress-website\/\" target=\"_blank\" rel=\"noopener\">secure WordPress fortress<\/a>.<\/p>\n\n\n\n<p>Hiding your version number only requires adding the following <a href=\"https:\/\/digwp.com\/2009\/07\/remove-wordpress-version-number\/\" target=\"_blank\" rel=\"noopener\">code snippet<\/a> to the functions file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">remove_action('wp_head', 'wp_generator');<\/pre>\n\n\n\n<p>The version number will now be removed from all areas of your site, including its code and your RSS feed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-5-automatically-update-your-copyright-notice\"><b>5. Automatically Update Your Copyright Notice<\/b><\/h3>\n\n\n\n<p>Updating the year in your copyright notice is one of those little tasks that\u2019s easy to forget. Fortunately, you can edit your functions file to automatically generate the copyright date based on the year when your first post was written.<\/p>\n\n\n\n<p>Paste <a href=\"https:\/\/premium.wpmudev.org\/blog\/daily-tip-how-to-add-a-dynamic-copyright-date-in-the-footer\/#comment-13309\" target=\"_blank\" rel=\"noopener\">the following code<\/a> into your functions file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">function wpb_copyright() {\nglobal $wpdb;\n$copyright_dates = $wpdb-&gt;get_results(\"\nSELECT\nYEAR(min(post_date_gmt)) AS firstdate,\nYEAR(max(post_date_gmt)) AS lastdate\nFROM\n$wpdb-&gt;posts\nWHERE\npost_status = 'publish'\n\");\n$output = '';\nif($copyright_dates) {\n$copyright = \"\u00a9 \" . $copyright_dates[0]-&gt;firstdate;\nif($copyright_dates[0]-&gt;firstdate != $copyright_dates[0]-&gt;lastdate) {\n$copyright .= '-' . $copyright_dates[0]-&gt;lastdate;\n}\n$output = $copyright;\n}\nreturn $output;\n}<\/pre>\n\n\n\n<p>Then add the following code wherever you want the copyright information to be displayed:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;?php echo wpb_copyright(); ?&gt;<\/pre>\n\n\n\n<p>You\u2019ll now see the dynamically updating copyright date on your site.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"1024\" height=\"92\" data-src=\"https:\/\/www.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-php-dynamic-auto-update-copyright-date-1024x92.png\" alt=\"A dynamically-updating copyright date on a website\" class=\"wp-image-37721 lazyload\" data-srcset=\"https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-php-dynamic-auto-update-copyright-date-1024x92.png 1024w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-php-dynamic-auto-update-copyright-date-300x27.png 300w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-php-dynamic-auto-update-copyright-date-768x69.png 768w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-php-dynamic-auto-update-copyright-date-1536x139.png 1536w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-php-dynamic-auto-update-copyright-date-600x54.png.webp 600w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-php-dynamic-auto-update-copyright-date-750x68.png.webp 750w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-php-dynamic-auto-update-copyright-date-100x9.png 100w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-php-dynamic-auto-update-copyright-date.png.webp 1695w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/92;\" \/><\/figure><\/div>\n\n\n<p>In our case, we added the date to the <i>footer.php<\/i> file, so it would be displayed at the bottom of the page.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-6-add-custom-menus\"><b>6. Add Custom Menus<\/b><\/h3>\n\n\n\n<p>Most themes have pre-defined <a href=\"https:\/\/www.dreamhost.com\/blog\/navigation-menu-design\/\" target=\"_blank\" rel=\"noopener\">navigation menus<\/a>. However, what if you want to create your own menu and place it wherever you want on your site?<\/p>\n\n\n\n<p>All you need to do is paste <a href=\"http:\/\/www.wpbeginner.com\/wp-themes\/how-to-add-custom-navigation-menus-in-wordpress-3-0-themes\/\" target=\"_blank\" rel=\"noopener\">this code<\/a> into your functions file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">function wpb_custom_new_menu() {\nregister_nav_menu('my-custom-menu',__( 'My Customized Menu' ));\n}\nadd_action( 'init', 'wpb_custom_new_menu' );<\/pre>\n\n\n\n<p>You can replace <i>\u2018My Customized Menu\u2019<\/i> with the name you want to give the menu. If you go to <i>Appearance &gt; Menus<\/i> in your admin area, you should see the new option listed on the page:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"1024\" height=\"254\" data-src=\"https:\/\/www.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-add-custom-menu-1024x254.jpg\" alt=\"customize your WordPress menus using the functions.php file\" class=\"wp-image-37716 lazyload\" data-srcset=\"https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-add-custom-menu-1024x254.jpg 1024w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-add-custom-menu-300x74.jpg 300w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-add-custom-menu-768x190.jpg 768w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-add-custom-menu-600x149.jpg.webp 600w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-add-custom-menu-750x186.jpg.webp 750w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-add-custom-menu-100x25.jpg 100w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-add-custom-menu.jpg.webp 1234w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/254;\" \/><\/figure><\/div>\n\n\n<p>You can now add the new menu anywhere on your site.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;?php\nwp_nav_menu( array(\n'theme_location' =&gt; 'my-custom-menu',\n'container_class' =&gt; 'custom-menu-class' ) );\n?&gt;<\/pre>\n\n\n\n<p>Most probably, you\u2019ll want to place this code in the <i>header.php<\/i> file. This will place the menu at the very top of your site.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-7-customize-your-excerpts\"><b>7. Customize Your Excerpts<\/b><\/h3>\n\n\n\n<p>Excerpts are short sample descriptions of your posts that you can display on your homepage or blog feed. By default, all excerpts have the same length and link text, but you can change that.<\/p>\n\n\n\n<p>First, let\u2019s alter the text of the link that takes you from the excerpt to the full post. This is usually \u201cRead more\u201d or \u201cContinue reading,\u201d but you can make it whatever you want by pasting <a href=\"https:\/\/codex.wordpress.org\/Customizing_the_Read_More\" target=\"_blank\" rel=\"noopener\">the following snippet<\/a> into your functions file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">function new_excerpt_more($more) {\nglobal $post;\nreturn '&lt;a class=\"moretag\" href=\"'. get_permalink($post-&gt;ID) . '\"&gt; Read the full article...&lt;\/a&gt;';\n}\nadd_filter('excerpt_more', 'new_excerpt_more');<\/pre>\n\n\n\n<p>Here, the link text has been set to <i>Read the full article&#8230;<\/i><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"1024\" height=\"363\" data-src=\"https:\/\/www.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-customize-post-excerpts-1024x363.jpg\" alt=\"customize WordPress excerpts by editing the functions.php file\" class=\"wp-image-37718 lazyload\" data-srcset=\"https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-customize-post-excerpts-1024x363.jpg 1024w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-customize-post-excerpts-300x106.jpg 300w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-customize-post-excerpts-768x273.jpg 768w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-customize-post-excerpts-600x213.jpg.webp 600w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-customize-post-excerpts-750x266.jpg.webp 750w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-customize-post-excerpts-100x35.jpg 100w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-customize-post-excerpts.jpg.webp 1082w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/363;\" \/><\/figure><\/div>\n\n\n<p>Then, let\u2019s change the length of the excerpt. Paste <a href=\"https:\/\/wp-snippets.com\/shorten-the-excerpt\/\" target=\"_blank\" rel=\"noopener\">this code<\/a> into your functions file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">function new_excerpt_length($length) {\nreturn 20;\n}\nadd_filter('excerpt_length', 'new_excerpt_length');<\/pre>\n\n\n\n<p>By default, the standard length is 55 words. However, in this example, it\u2019s been set to 20. You can change the number to whatever you wish.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-8-generate-a-random-background-to-your-site\"><b>8. <\/b><b>Generate<\/b><b> a Random Background to Your Site<\/b><\/h3>\n\n\n\n<p>Finally, let\u2019s end with a fun design trick. This tweak lets you randomly generate a new background color for your site every time somebody visits it. Start by adding <a href=\"https:\/\/gist.github.com\/rwdevpixelparlor\/601157cefc1cdd1a2fa1c27d569bbdfe\" target=\"_blank\" rel=\"noopener\">the following code<\/a> to the functions file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">function wpb_bg() {\n$rand = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');\n$color ='#'.$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].\n$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)];\necho $color;\n}<\/pre>\n\n\n\n<p>This code generates the HTML tag for the colors, so all you need to do now is to make sure it gets applied to the page. To do that, you\u2019ll need to find the &lt;body&gt; tag, which should look like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;body &lt;?php body_class(); ?&gt;&gt;<\/pre>\n\n\n\n<p>This is usually in the <i>header.php<\/i> file but can be elsewhere, depending on your theme. When you\u2019ve located the right line, simply replace it with the following code:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;body &lt;?php body_class(); ?&gt; style=\"background-color:&lt;?php wpb_bg();?&gt;\"&gt;&gt;<\/pre>\n\n\n\n<p>Save your file and open your website. You should see that it has a new background color:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"1024\" height=\"552\" data-src=\"https:\/\/www.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-generate-random-background-color-2-1024x552.jpg\" alt=\"create random background colors on reload by editing your WordPress functions.php file\" class=\"wp-image-37719 lazyload\" data-srcset=\"https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-generate-random-background-color-2-1024x552.jpg 1024w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-generate-random-background-color-2-300x162.jpg 300w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-generate-random-background-color-2-768x414.jpg 768w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-generate-random-background-color-2-1536x828.jpg 1536w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-generate-random-background-color-2-600x324.jpg.webp 600w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-generate-random-background-color-2-750x404.jpg.webp 750w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-generate-random-background-color-2-100x54.jpg 100w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-generate-random-background-color-2.jpg.webp 1999w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/552;\" \/><\/figure><\/div>\n\n\n<p>Reload the page, and you\u2019ll see a new color every time:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"1024\" height=\"552\" data-src=\"https:\/\/www.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-generate-random-background-color-1024x552.jpg\" alt=\"create random background colors on reload by editing your WordPress functions.php file\" class=\"wp-image-37720 lazyload\" data-srcset=\"https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-generate-random-background-color-1024x552.jpg 1024w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-generate-random-background-color-300x162.jpg 300w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-generate-random-background-color-768x414.jpg 768w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-generate-random-background-color-1536x828.jpg 1536w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-generate-random-background-color-600x324.jpg.webp 600w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-generate-random-background-color-750x404.jpg.webp 750w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/wordpress-functions-generate-random-background-color-100x54.jpg 100w, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/smush-webp\/2022\/10\/wordpress-functions-generate-random-background-color.jpg.webp 1999w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/552;\" \/><\/figure><\/div>\n\n\n<p>This is obviously not the right design choice for every site, but it\u2019s a neat trick for some!<\/p>\n\n\n\n<h2 id=\"h-edit-your-functions-php-file\" class=\"wp-block-heading\"><b>Edit Your functions.php File<\/b><\/h2>\n\n\n\n<p>The WordPress <i>functions.php<\/i> file is the perfect place to tinker with your site\u2019s default functionality. It\u2019s a powerful file that gives you a lot of control over your site once you understand how it works.<\/p>\n\n\n\n<p>Depending on your WordPress theme, you might be able to use the built-in Theme File Editor to access and edit your functions.php file. Otherwise, you can access it via FTP. Then, you can use custom code to do everything from displaying the estimated reading time of a post to customizing your excerpts.<\/p>\n\n\n\n\n\n<div\n\tclass=\"article-cta-shared article-cta-small\"\n>\n    <div class=\"tr-img-wrap-outer jsLoading\"><img decoding=\"async\" class=\"js-img-lazy \" src=\"https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/themes\/blog2018\/assets\/img\/lazy-loading-transparent.webp\" data-srcset=\"https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/themes\/blog2018\/assets\/img\/article-small-ad-cta-placeholder.webp 1x, https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/themes\/blog2018\/assets\/img\/article-small-ad-cta-placeholder-x2.webp 2x\"  alt=\"Ad background image\" \/><\/div>\n\n\n\n\n  <div class=\"content-btm\">\n    <h2\n      class=\"h2--md\"\n    >\n      Do More with DreamPress\n    <\/h2>\n    <p\n      class=\"p--md\"\n    >\n      DreamPress Plus and Pro users get access to Jetpack Professional (and 200+ premium themes) at no added cost!\n    <\/p>\n\n            <a\n            href=\"https:\/\/www.dreamhost.com\/wordpress\/managed\/\"\n                        class=\"btn btn--white-outline btn--sm btn--round\"\n                                    target=\"_blank\"\n            rel=\"noopener noreferrer\"\n            >\n                            Check Out Plans                    <\/a>\n\n  <\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>To get involved in WordPress development, you\u2019ll first need to understand how the platform\u2019s most important files work. WordPress makes it pretty easy to tinker with your site. However, it can be difficult to know where to start \u2014 or predict what your changes will actually do. A perfect place to learn is the functions.php [&hellip;]<\/p>\n","protected":false},"author":1062,"featured_media":37713,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_yoast_wpseo_metadesc":"The WordPress functions.php file enables you to add custom code to your site, unlocking new features and functionality. Learn more.","toc_headlines":"[[\"h-what-is-the-functions-php-file\",\"<b>What Is the functions.php File?<\/b>\"],[\"h-how-to-edit-the-functions-file-2-methods\",\"<b>How to Edit the Functions File (2 Methods)<\/b>\"],[\"h-8-tricks-you-can-accomplish-with-the-wordpress-functions-file\",\"<b>8 Tricks You Can Accomplish With the WordPress Functions File<\/b>\"],[\"h-edit-your-functions-php-file\",\"<b>Edit Your functions.php File<\/b>\"]]","hide_toc":false,"footnotes":""},"categories":[13129,550,696],"tags":[],"class_list":["post-37708","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developer-central","category-tutorials","category-wordpress"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.3 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Your Guide to the WordPress functions.php File - DreamHost<\/title>\n<meta name=\"description\" content=\"The WordPress functions.php file enables you to add custom code to your site, unlocking new features and functionality. Learn more.\" \/>\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-dev.dreamhost.com\/blog\/guide-to-wp-functions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Everything You Need to Know About the WordPress functions.php File\" \/>\n<meta property=\"og:description\" content=\"The WordPress functions.php file enables you to add custom code to your site, unlocking new features and functionality. Learn more.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www-dev.dreamhost.com\/blog\/guide-to-wp-functions\/\" \/>\n<meta property=\"og:site_name\" content=\"DreamHost Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DreamHost\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-25T14:00:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-22T05:20:57+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/WordPress-Functions.php-Social.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Jason Cosper\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@dreamhost\" \/>\n<meta name=\"twitter:site\" content=\"@dreamhost\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jason Cosper\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Your Guide to the WordPress functions.php File - DreamHost","description":"The WordPress functions.php file enables you to add custom code to your site, unlocking new features and functionality. Learn more.","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-dev.dreamhost.com\/blog\/guide-to-wp-functions\/","og_locale":"en_US","og_type":"article","og_title":"Everything You Need to Know About the WordPress functions.php File","og_description":"The WordPress functions.php file enables you to add custom code to your site, unlocking new features and functionality. Learn more.","og_url":"https:\/\/www-dev.dreamhost.com\/blog\/guide-to-wp-functions\/","og_site_name":"DreamHost Blog","article_publisher":"https:\/\/www.facebook.com\/DreamHost\/","article_published_time":"2022-10-25T14:00:06+00:00","article_modified_time":"2025-05-22T05:20:57+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/www.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/WordPress-Functions.php-Social.jpg","type":"image\/jpeg"}],"author":"Jason Cosper","twitter_card":"summary_large_image","twitter_creator":"@dreamhost","twitter_site":"@dreamhost","twitter_misc":{"Written by":"Jason Cosper","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www-dev.dreamhost.com\/blog\/guide-to-wp-functions\/#article","isPartOf":{"@id":"https:\/\/www-dev.dreamhost.com\/blog\/guide-to-wp-functions\/"},"author":{"name":"Jason Cosper","@id":"https:\/\/www-dev.dreamhost.com\/blog\/#\/schema\/person\/2273b8bf7336df78f6d99a89c17253c4"},"headline":"Everything You Need to Know About the WordPress functions.php File","datePublished":"2022-10-25T14:00:06+00:00","dateModified":"2025-05-22T05:20:57+00:00","mainEntityOfPage":{"@id":"https:\/\/www-dev.dreamhost.com\/blog\/guide-to-wp-functions\/"},"wordCount":1794,"publisher":{"@id":"https:\/\/www-dev.dreamhost.com\/blog\/#organization"},"image":{"@id":"https:\/\/www-dev.dreamhost.com\/blog\/guide-to-wp-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/WordPress-Functions.php-Feature.jpg","articleSection":["Developer Central","Tutorials","WordPress"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www-dev.dreamhost.com\/blog\/guide-to-wp-functions\/","url":"https:\/\/www-dev.dreamhost.com\/blog\/guide-to-wp-functions\/","name":"Your Guide to the WordPress functions.php File - DreamHost","isPartOf":{"@id":"https:\/\/www-dev.dreamhost.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www-dev.dreamhost.com\/blog\/guide-to-wp-functions\/#primaryimage"},"image":{"@id":"https:\/\/www-dev.dreamhost.com\/blog\/guide-to-wp-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/WordPress-Functions.php-Feature.jpg","datePublished":"2022-10-25T14:00:06+00:00","dateModified":"2025-05-22T05:20:57+00:00","description":"The WordPress functions.php file enables you to add custom code to your site, unlocking new features and functionality. Learn more.","breadcrumb":{"@id":"https:\/\/www-dev.dreamhost.com\/blog\/guide-to-wp-functions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www-dev.dreamhost.com\/blog\/guide-to-wp-functions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www-dev.dreamhost.com\/blog\/guide-to-wp-functions\/#primaryimage","url":"https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/WordPress-Functions.php-Feature.jpg","contentUrl":"https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/10\/WordPress-Functions.php-Feature.jpg","width":900,"height":598,"caption":"WordPress functions.php file"},{"@type":"BreadcrumbList","@id":"https:\/\/www-dev.dreamhost.com\/blog\/guide-to-wp-functions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dhblog.dream.press\/blog\/"},{"@type":"ListItem","position":2,"name":"Everything You Need to Know About the WordPress functions.php File"}]},{"@type":"WebSite","@id":"https:\/\/www-dev.dreamhost.com\/blog\/#website","url":"https:\/\/www-dev.dreamhost.com\/blog\/","name":"DreamHost Blog","description":"","publisher":{"@id":"https:\/\/www-dev.dreamhost.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www-dev.dreamhost.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www-dev.dreamhost.com\/blog\/#organization","name":"DreamHost","url":"https:\/\/www-dev.dreamhost.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www-dev.dreamhost.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/dhblog.dream.press\/blog\/wp-content\/uploads\/2019\/01\/dh_logo-blue-2.png","contentUrl":"https:\/\/dhblog.dream.press\/blog\/wp-content\/uploads\/2019\/01\/dh_logo-blue-2.png","width":1200,"height":168,"caption":"DreamHost"},"image":{"@id":"https:\/\/www-dev.dreamhost.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DreamHost\/","https:\/\/x.com\/dreamhost","https:\/\/www.instagram.com\/dreamhost\/","https:\/\/www.linkedin.com\/company\/dreamhost\/","https:\/\/www.youtube.com\/user\/dreamhostusa"]},{"@type":"Person","@id":"https:\/\/www-dev.dreamhost.com\/blog\/#\/schema\/person\/2273b8bf7336df78f6d99a89c17253c4","name":"Jason Cosper","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/02\/IMG_4807-scaled.jpeg","url":"https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/02\/IMG_4807-scaled.jpeg","contentUrl":"https:\/\/www-dev.dreamhost.com\/blog\/wp-content\/uploads\/2022\/02\/IMG_4807-scaled.jpeg","caption":"Jason Cosper"},"description":"Jason is DreamHost\u2019s WordPress Product Advocate, based out of Bakersfield, CA. He is currently working on making our DreamPress product even better. In his free time, he likes to curl up on the couch and watch scary movies with his wife Sarah and three very small dogs. Follow him on Twitter.","url":"https:\/\/www-dev.dreamhost.com\/blog\/author\/jasoncosper\/"}]}},"lang":"en","translations":{"en":37708,"es":37728,"de":52356,"pl":55749,"pt":55782,"ru":55804,"uk":55807,"it":68777,"fr":71157,"nl":71182},"pll_sync_post":[],"_links":{"self":[{"href":"https:\/\/www-dev.dreamhost.com\/blog\/wp-json\/wp\/v2\/posts\/37708","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www-dev.dreamhost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www-dev.dreamhost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www-dev.dreamhost.com\/blog\/wp-json\/wp\/v2\/users\/1062"}],"replies":[{"embeddable":true,"href":"https:\/\/www-dev.dreamhost.com\/blog\/wp-json\/wp\/v2\/comments?post=37708"}],"version-history":[{"count":7,"href":"https:\/\/www-dev.dreamhost.com\/blog\/wp-json\/wp\/v2\/posts\/37708\/revisions"}],"predecessor-version":[{"id":61506,"href":"https:\/\/www-dev.dreamhost.com\/blog\/wp-json\/wp\/v2\/posts\/37708\/revisions\/61506"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www-dev.dreamhost.com\/blog\/wp-json\/wp\/v2\/media\/37713"}],"wp:attachment":[{"href":"https:\/\/www-dev.dreamhost.com\/blog\/wp-json\/wp\/v2\/media?parent=37708"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www-dev.dreamhost.com\/blog\/wp-json\/wp\/v2\/categories?post=37708"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www-dev.dreamhost.com\/blog\/wp-json\/wp\/v2\/tags?post=37708"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}