For beginner level web developers or those wishing to build on their WordPress sites, the functions.php file must have come to your attention. It is one of the most effective tools to help you configure the workings of your website without having to waste too much time on plugins. This guide shows you how to find, open, and modify the functions.php file. So, let us get started!
- What Does the WordPress functions.php File Do?
- Where is the functions.php File Located?
- How To Safely Work With the functions.php File
- How to Access functions.php in 3 Easy Methods
- 15 Useful Functions to Add to Your WordPress functions.php File
- Show Last Modified Date on Blog Posts
- Disable the WordPress Toolbar for Certain Users
- Delay Posts from Appearing In RSS Feed
- Exclude Certain Categories From RSS Feed
- Limit WordPress Revisions by Post Type
- Disable the WordPress Search Function
- Allow Shortcodes in Post Titles
- Hide Login Errors to Improve Security
- Change the Excerpt Length
- Remove the WordPress Version Number
- Change How Many Results to Include on Search Listing Page
- Include Featured Images in the WordPress RSS Feed
- Add Upload Support for File Types (E.g., SVG)
- Hide WordPress Update Nags for Non-Administrators
- Change Automatic JPEG Optimization Quality
- How to Protect functions.php from Security Exploits
- Best Practices for Organizing Your WordPress functions.php File
- Summary
- Frequently Asked Questions
What Does the WordPress functions.php File Do?
The first question is – what is this file and why does it exist? Just imagine a toolbox that comes with a Swiss knife, one of the tools is your WordPress theme. It gives you the leverage to add a set of new features or modify the existing ones. For example, you are able to:
- Enable or add new customizations such as menus or widgets.
- Change the way posts appear on your website.
- Disable or enable specific functions like admin toolbar or post revisions.
In a nutshell, these tasks can be accomplished and more! They are just snippets and can be added to the file without the extensive use of plugins which many never want to do. If you are using Cloudways for hosting WordPress websites, it is easy to edit and customize your functions.php website.
Where is functions.php File in WordPress?
Let’s learn where functions.php file is located. It is found in the active theme’s folder. This is how to find it:
Editing the functions. It is a little risk of doing this if you are not smart enough. Here are a few tips about how to avoid getting into trouble:
Be sure to test your code on a staging site before making any changes to your live site.
- Open Your WordPress Dashboard: You will need to access your WordPress admin dashboard.
- Go to Appearance: Click on “Appearance” in the left sidebar and then on “Theme Editor.”
- Find the functions.php File: On the right side of the Theme Editor, you’ll see a list of files. Look for one named functions.php.

If you’re using a child theme (which is a smart move!), you’ll find a separate functions.php file in that folder as well. If you don’t see it listed in the Theme Editor, you can also access it via SFTP or SSH as outlined in later sections.
Ready to take control of your WordPress site?
With Cloudways, you can easily manage your hosting needs—whether you’re securing your website or looking for a reliable host for your site. Join the Cloudways family today and experience hassle-free WordPress hosting that puts you in charge.
How To Safely Work With the functions.php File
Editing the functions. It is a little risk of doing this if you are not smart enough. Here are a few tips about how to avoid getting into trouble.
Test Your functions.php Code on a Staging Site
Be sure to test your code on a staging site before making any changes to your live site.In this way, you can play with it without ruining your real website. Several hosting providers even offer easy options to create staging sites. For instance, Cloudways has built-in staging features that lets you create a staging site of your live site just in a few clicks.
Back Up Your Site Before Making Changes to functions.php
Always back up your site before diving into changes! If anything goes awry, you want to be able to swiftly revert your site. You may leverage updraft plus or backup buddy for this. Just install any of these, set it up according to your need, and create a back up before proceeding with any changes. If you are a Cloudways user, don’t worry we got you covered. Your website gets automatically backed up on regular basis by default with Cloudways Backup & Restore feature.
Always Use a Child Theme If You’re Editing the functions.php File
When planning on making changes directly into the functions.php, consider using a child theme. This way, the changes will remain even after the parent theme gets updated. A child theme will let you keep all your customization while receiving updates from the parent theme developer.
How to Access functions.php in 3 Easy Methods
There are several ways to access and edit the functions.php file. Let me show you three simple methods:
Method 1: Accessing functions.php in the WordPress Theme File Editor
- Log into Your Dashboard: Go to Appearance > Theme Editor.
- Select functions.php: From the list of files on the right, click on functions.php.
- Make Your Edits: You can now add or modify code here directly in the editor.
- Update File: Once done with your changes, click “Update File” at the bottom.
This method is straightforward but be cautious! If there are errors in your code, they could cause issues with your site.
Method 2: Accessing functions.php via SFTP
Using an SFTP client like FileZilla is another great option:
- Connect to Your Server: Use your SFTP credentials (you can find these in your hosting account).
- Navigate to Your Theme Folder: Go to wp-content/themes/your-active-theme/.
- Download functions.php: Save it locally on your computer.
- Edit It: Open it with a text editor (like Notepad++ or Sublime Text) and make your changes.
- Upload It Back: Once edited, upload it back to the same folder.

Access-functions.php-file-using-SFTP
This method allows for more control over editing and is often safer than using the built-in editor.
Performance-Focused WordPress Hosting from $11/Month
Experience Hassle-free WordPress Hosting. Start now and see how easy it is to run your website!
Method 3: Accessing functions.php via SSH
For those who are comfortable with the command line tools, this method is for you:
- SSH Connection: Use your SSH client (like PuTTY) and log into your server. If you are Cloudways User, you can easily launch SSH terminal from your Cloudways Platform and use the Master Credentials to connect with your server.
- Go to your theme directory: Type cd wp-content/themes/your-active-theme/.
- Edit functions.php: Open it with a command-line text editor like nano or vim (e.g. nano functions.php).

Editing via SSH can be exceptionally powerful but requires a little more knowledge to manage command-line operations.
15 Useful Functions to Add to Your WordPress functions.php File
Now that you know how to access the file, let’s take a look at some fancy code snippets you can add! These will definitely make your site more functional without getting into cross-programque interactions or going through the headache of installing more plugins.
Show Last Modified Date on Blog Posts
This snippet displays the last modified date of blog posts below their content. You can place this code at the end of your functions.php file or anywhere before ?> if it exists.
function show_last_modified_date() {
echo 'Last modified: ' . get_the_modified_time('F j, Y');
}
add_action('the_post', 'show_last_modified_date');
Disable the WordPress Toolbar for Certain Users
This code hides the admin toolbar for all users except administrators. Add this snippet towards the end of functions.php.
if (!current_user_can('administrator')) {
add_filter('show_admin_bar', '__return_false');
}
Delay Posts from Appearing In RSS Feed
This snippet prevents posts from appearing in RSS feeds until one week after their publication. Place this code towards the end of functions.php.
function delay_rss_feed($query) {
if ($query->is_feed) {
$query->set('date_query', array(
array(
'after' => '1 week ago',
),
));
}
return $query;
}
add_action('pre_get_posts', 'delay_rss_feed');
Exclude Certain Categories From RSS Feed
If you want to exclude specific categories from RSS feeds, use this code snippet. Just replace -4 with the ID of the category you want excluded.
function exclude_category_from_feed($query) {
if ($query->is_feed) {
$query->set('cat', '-4'); // Replace 4 with category ID
}
return $query;
}
add_action('pre_get_posts', 'exclude_category_from_feed');
Limit WordPress Revisions by Post Type
This parameter limits post revisions for all post types. Add this at any point in functions.php, preferably near other configuration settings.
define(‘WP_POST_REVISIONS’, 5); // Limit revisions to 5
Disable the WordPress Search Function
This snippet redirects users away from search results. Place this towards the end of functions.php.
function disable_search() {
if (is_search()) {
wp_redirect(home_url());
exit();
}
}
add_action('template_redirect', 'disable_search');
Allow Shortcodes in Post Titles
This allows shortcodes within post titles. You can add this snippet anywhere in functions.php.
add_filter('the_title', 'do_shortcode');
Hide Login Errors to Improve Security
This parameter hides specific error messages during login attempts. Place this code towards the end of functions.php.
add_filter('login_errors', function() { return ' '; });
Change the Excerpt Length
This function adjusts how many words appear in post excerpts. Add this at any point in functions.php.
function custom_excerpt_length($length) {
return 20; // Change number for desired length
}
add_filter('excerpt_length', 'custom_excerpt_length');
Remove the WordPress Version Number
This parameter removes version information from HTML headers for security reasons. Place this snippet near other security-related codes.
remove_action('wp_head', 'wp_generator');
Change How Many Results to Include on Search Listing Page
You can modify how many search results are returned. Adjust 10 as needed based on how many results you’d like displayed.
function custom_search_results($query) {
if ($query->is_search) {
$query->set('posts_per_page', 10); // Change number as needed
}
return $query;
}
add_action('pre_get_posts', 'custom_search_results');
Include Featured Images in the WordPress RSS Feed
This adds featured images into RSS feeds. Place this towards the end of functions.php.
function rss_featured_image($content) {
global $post;
if (has_post_thumbnail($post->ID)) {
$content = '<p>' . get_the_post_thumbnail($post->ID) . '</p>' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'rss_featured_image');
Add Upload Support for File Types (E.g., SVG)
This function enables SVG uploads by modifying allowed MIME types. Add this snippet towards the end of functions.php.
function cc_mime_types($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
Hide WordPress Update Nags for Non-Administrators
It hides update notifications from non-admin users. Place this code towards the end of functions.php.
if (!current_user_can('administrator')) {
add_filter('pre_site_transient_update_core', '__return_null');
add_filter('pre_site_transient_update_plugins', '__return_null');
add_filter('pre_site_transient_update_themes', '__return_null');
}
Change Automatic JPEG Optimization Quality
This adjusts JPEG image quality upon upload. You can place this anywhere within functions.php.
add_filter('jpeg_quality', function($arg) { return 80; }); // Change quality as needed
How to Protect functions.php from Security Exploits
Keeping your site secure is crucial! Here are some tips on how to protect your functions.php file from potential threats:
1. Install a Security Plugin
As a thought if you are having one security plugin against your site like Wordfence or Sucuri, it can take over and help you monitor and protect your website against vulnerabilities by scanning for malware or any unauthorized changes.
2. Deny Access via .htaccess
You can restrict access by adding rules in your .htaccess file:
<Files "functions.php"> Order Allow,Deny Deny from all </Files>

-Htaccess File
You can add the code at the top of your .htaccess file. This prevents anyone from accessing functions.php directly through a web browser.
3. Deny Access Using Code
You can also restrict access within functions.php itself:
if (!current_user_can('administrator')) {
exit; // Prevent access for non-admin users
}
This ensures that only administrators can run any code within that file. You can add it to the bottom of your functions.php file.
4. Hide functions.php Outside of Root Directory
It could be a good idea to move the functions.php file out of the web root directory to add extra security against unauthorized access, for any files you put in the root directory can directly be accessed via a web browser.
- Create a New Directory: Create a folder outside your web root (e.g., secure_files in the parent directory of public_html).
- Download Your Current functions.php: Use an SFTP client or the WordPress Theme Editor to download your existing functions.php file.
- Upload to the New Directory: Upload the functions.php file to your new directory (secure_files/functions.php).
- Modify WordPress to Include It: Update your theme’s main functions.php file to point to the new location Replace /path/to/your/secure_files/ with the actual path.:
include_once('/path/to/your/secure_files/functions.php');
- Test Your Site: Ensure everything works correctly and that all custom functionalities are intact.
Best Practices for Organizing Your WordPress functions.php File
Keeping things tidy will save you headaches down the road! Here are some best practices:
Add Code Comments
Commenting on your code helps others (and future you!) understand what each section does:
// This function shows last modified date on blog posts
function show_last_modified_date() { ... }
Good comments make maintenance easier down the line. You can refer to the code block above.
Use Include Files
If you have more than one snippet to add, then you can consider creating separate PHP files to include them all in your functions.php:
include_once get_template_directory() . '/custom-functions/my-custom-function.php';
This approach is useful and it keep things organized and manageable.
Explore Alternatives
If you’re hesitant about editing directly in functions.php, consider using plugins or creating custom functionality plugins instead:
- Plugins like Code Snippets allow you to safely manage custom PHP code without directly modifying theme files.
- Custom functionality plugins let you bundle multiple snippets together while keeping them separate from themes.
Scale Seamlessly with Cloudways Autonomous
Bid farewell to traffic worries. Cloudways Autonomous effortlessly handles your website’s growth, ensuring smooth operations no matter the surge.
Summary
The functions.php file is the core of customizing your WordPress experience! Understanding its purpose and safely upgrading it can greatly improve the usability of your site while keeping everything secure and neat. Cloudways combines powerful performance features with usability to form a seamless managed hosting solution that caters to WordPress users. However, apart from WordPress Cloudways also supports PHP, Laravel, Magento and Drupal hosting.
For those looking to make the most of their WordPress experience without having to deal with the normal hassles of hosting solutions, Cloudways proves to be an excellent option that eases management while powering high performance and security. They provide their users with the effective tools to optimize fast, secure, and reliable WordPress sites, be they beginners or expert developers. While you continue your exploration into web development, always remember that careful coding will save your time and headaches in the long run! Happy coding!
Q. What happens if I make a mistake while editing functions.php file?
A. It could lead to errors like the “White Screen of Death”! That’s why backup is really important!
Q. Can I use multiple code snippets in functions.php file?
A. Absolutely! Just keep them organized so they’re easy to manage and understand later on.
Q. Will my changes persist in functions.php file after updates?
A. Changes made directly in functions.php will be lost upon updates unless you’re using a child theme.
Salwa Mujtaba
Salwa Mujtaba is a Technical Content Writer at Cloudways. With a strong background in Computer Science and prior experience as a team lead in Cloudways Operations, she brings a deep understanding of the Cloudways Platform to her writing. Salwa creates content that simplifies complex concepts, making them accessible and engaging for readers. When she's not writing, you can find her enjoying good music, reading a book, or spending quality time with her family.