Some Useful and Important Custom Code add to WordPress funtions.php file

-

Affiliate Disclosure: Every purchase made through our affiliate links earns us a pro-rated commission without any additional cost to you. Here are more details about our affiliate disclosure.

In WordPress, functions.php or the theme functions file is a template included in WordPress themes. It acts like a plugin for your WordPress site that’s automatically activated with your current theme. The functions.php file uses PHP code to add features or change default features on a WordPress site.

For example, a WordPress theme might add a bit of code to the theme’s functions.php file in order to add a new widget area to the footer, or add a custom welcome message to the WordPress dashboard. The possibilities are endless!

The functions.php file automatically loads when you install and activate a theme on your WordPress site.

Editing the functions.php file using custom codes allows you to add post types, taxonomies, shortcodes, and more to improve your website.

Where Is the Functions.php File Located?

The functions.php file location is in your theme folder.

If you want to add a code snippet to your WordPress site, adding it to the functions.php file is one option.

But it’s usually not the best way to do it. WordPress tries to separate design and functionality whenever possible. This is the reason that we have themes, which determine the design, and plugins, which determine functions.

It’s best if you’re able to change your WordPress theme without changing the way your site functions, or change your plugins without affecting your site design.

If you decide to edit your functions.php file, please use extreme caution. Here are 3 reasons why editing your functions.php file is not a good idea:

  • Edits to the functions file will be lost when the theme is updated.
  • Edits will be lost if you change your WordPress theme.
  • Making coding errors in the functions file can lock you out of your site.

Even something as simple as a missing semicolon could make your whole site disappear with an error called the “White Screen of Death”. If that does happen to you, we wrote a step-by-step guide on how to fix the WordPress White Screen of Death so you can regain access to your site.

Making a coding mistake in your functions.php file can also lead to other WordPress errors as well.

You should only edit a functions.php file if you have a child theme and the code snippets will only be used with the active child theme. For example, you may want to include snippets for custom fonts, stylesheets, or add a language translation file specifically for that particular child theme.

How to keep users logged-in in WordPress

Keeping users logged-in is extremely important, so they don’t have to login everytime they open their app.

In some cases the user login time might be affected by your server configuration or even third-party plugins installed on your website.

Below you can see a function that will help with adjusting the login duration in WordPress, the code must be placed in your theme’s functions.php file:

// keep users logged in for longer in wordpress
function keep_users_logged_in_longer( $expirein ) {
    // 1 month in seconds
    return 2628000;
}
add_filter( 'auth_cookie_expiration', 'keep_users_logged_in_longer' );
Related Articles

Like our Article/ Blog? Can buy a Buttermilk for our team.. Click here

Pardeep Patelhttps://pardeeppatel.com/
Hi!, I am Pardeep Patel, an Indian passport holder, Traveler, Blogger, Story Writer. I completed my M-Tech (Computer Science) in 2016. I love to travel, eat different foods from various cuisines, experience different cultures, make new friends and meet other.

Share this article

-- Advertisement --

LEAVE A REPLY

Please enter your comment!
Please enter your name here

-- Advertisement --