What is and how the functions.php file is used • WordPress Help

 functions functions.php

It is usual to find in Help WordPress crowd of tricks to add features to the file functions.php we have even talked about if it is better to use this file or a utilities plugin which we also learned to do but what is the file functions.php and how to use ?

Let's look at some basics and how to use it, how do you like it?

What is the functions file .php?

The most basic thing is that it is a PHP file, that is, a text file full of characters and spaces that the PHP engine will run to do things on your website. These characters are called functions and are enclosed between the tags <? Php and ?> . The thing is simple: what is inside those tags is executed and what is out is not .

It comes to be the natural, and better structured replacement of the veteran file my-hacks. php disappeared in WordPress 2.8 which was where formerly extra features were included, but with the aggravating circumstance that in each WordPress update the file was crushed.

Where is the file functions .php?

Virtually all current WordPress themes have a file functions.php in the main folder, and if you do not have it, you should have it. Sometimes it contains many functions and sometimes only a few.

What does the functions.php file do?

The file functions.php contains some PHP codes called functions, a standard feature of WordPress that allows a theme to "connect" with WordPress internal features (register sidebars, add thumbnail support, etc.) or own the active theme, such as specialized short codes.

How does WordPress communicate with the file functions.php?

WordPress, by default, expects to find a file functions.php in the folder of the active theme, nothing happens if it is not found, but WordPress checks to see if it exists and interacts with it, executing the functions that it finds.

In this way, WordPress "knows" that the functions located in the file functions.php of your theme must be executed and it will use the PHP engine installed n the server and the standard functions of WordPress to interpret and execute them. It seems complicated but it is simple, it is based on the functions themselves and on other pieces of code called " hooks " (hooks) .

Do I need a functions.php file?

Essential is not, but it is highly recommended. You can include in it functions necessary for the theme to work correctly, and as it is the first WordPress review will be loaded immediately, before plugin codes, because ultimately the first thing that should be shown is the design, ie , the subject.

Tips for using the file functions.php

Despite the interesting thing about having a file functions.php in the active theme, there are some tips to keep in mind:

  • Do not go crazy adding functions to file functions.php . This file is great to include in it functions related to the design, with visual elements, for the rest of things a utilities plugin is better. There are many people who use the file functions.php to put in it all the cool features found in WordPress Help or any other web, and no, it's not a mixed bag, each function that you include must have a meaning and purpose, and if you do not use it, delete it.
  • The file functions.php of a theme child does not overlap that of the parent theme unlike the rest of files that you create in the child theme . If it will be executed before the parent theme, which will be a problem if there are the same or incompatible functions, which would result in ugly PHP errors of duplicate functions or something much worse, so check what you put in the file functions.php of the son and the father theme.
  • Try not to grow too much it does not matter if you need many functions. If you see that your file functions.php begins to skim 200 lines seriously consider creating dependent files from which your file functions.php extracts the rest of the codes that you want to execute, you can easily do using PHP commands like include () or require () which will include or make the necessary connection to run everything without the need to overload your file functions. php .

As you will see, the file functions.php is of great use and used sparingly will expand and improve the functionality of your web, so learn to use it, treat it with affection and add useful functions.

NOTICE : this publication is from two years ago or more. If it's a code or a plugin it might not work in the latest versions of WordPress, and if it's a news story it might be obsolete. Then do not say we have not warned you.

Loading …

That may also help you:

List of the last registered users • WordPress Help

 users wordpress

If you have an important community every element that makes the sense of belonging is vital, and you should not waste any opportunity of that the users of your site feel integrated .

This, with a BuddyPress installation, is simple, since it offers widgets of all kinds to show groups, users connected or new users, but what happens in a WordPress " normal "? without additions.

One of the vital elements for fidelizar generate conversation and community is to show a list of new users, of the last ones that have registered and for it you only have to add a small code to your sidebar (for example), something like this: [19659006] Newcomers

get_results ("SEL ECT user_nicename, user_url FROM $ wpdb-> users ORDER BY ID DESC LIMIT 5 ");
        foreach ($ usernames as $ username) {
                echo '

  • ' .get_avatar ($ username-> comment_author_email, 45). '

      ] The newcomers

      <? Php $ usernames = $ wpdb -> get_results ( "SELECT user_nicename, user_url FROM $ wpdb-> users ORDER BY ID DESC LIMIT 5" ) ;

      [19659021] foreach ( $ usernames as $ username ) { echo '

    • ' . get_avatar ( $ username -> comment_author_email 45 ) . '< a href = "'. $ username -> user_url . '"> '. $ username -> ] ; ; ; ]

  • What makes this code, apart from giving a title to the block (the defined by h3 ), is to retrieve the list of users and display the last 5 registered, then display them by their username chosen in the WordPress profile, next to their gravatar in a decent size (45), which is not too big, and with the name linked to its author page, there is nothing.

    Nice trick shared by emobot

    NOTICE : this publication is from two years ago or plus. If it's a code or a plugin it might not work in the latest versions of WordPress, and if it's a news story it might be obsolete. Then do not say we have not warned you.

    Loading …

    That may also help you: