0

I have gone through some tutorials and I found that for every HTML to wordpress theme conversion, they write function.php file.

Now I noticed that there is some common lines in that function.php.So is it common line for every theme or is it different ?

2

To start off, a theme does not require a functions.php file to operate. For example, a one page site can simply just have an index.php and a style.css file.

Your functions.php file holds functions, filters and action hooks to add theme specific functionality to your site. This extends core functions, add complete new functionality or even remove existing core functionality.

Each theme's functions.php is unique to the theme, depending on the theme's and end user's needs for certain functionalities, although some functionalities might be found in other themes as well. These functionalities which are widely used in most themes includes things like adding theme support for thumbnails, adding navigation menus, adding widgets and sidebars and adding styles/scripts to the theme

It is also important to know that coding styles differ from person to person, so the same exact functionality can differ in code from one theme to the other depending on the author's coding style. It come down to many ways to skin a cat.

I think the most important aspect to take into consideration when converting/creating/modifying a theme is what goes into your functions file and what does not. As I said, a theme functions.php is meant for theme specific functionalities, not for a site's functionalities. My tip would be is to go and sit down, make a list of what functionalities to you need, and then decide whether the specific function is needed by the theme to make the theme functional, or is it needed to make the site functional. If a function is needed by the site, and not the theme, those functions should be added to a functionality plugin, and not the theme's functions.php

Resources:

1
  • Did you find any answer useful. If so, and it solved your issue, please select that answer and accept it. If none answered your question, and you need more info, please file an edit on your original question and explain what further info is needed. Please help us keep your question and this site constructive Sep 9 '14 at 5:59
1

Most theme's functions.php start the with the same boilerplate code and then is altered as the theme advances. Although they may have common features, they will vary among themes. For example, most themes make use of widget areas (sidebars). But there are many different configurations of them from the number of areas to the classnames or the type of elements used.

You'll see the variances as you move beyond the tutorials.

0

Each theme has a different functions.php, of course some code could be similar in different themes, but the functions in the file are used by the theme.

You can use it to create custom functions, and for clarity and to separate view and logic, you add that functions to the functions.phptheme.

Also, you have to take into account that Wordpress executes the functions.php early in the cicle, so you can add filter to change how things work, for example using the pre_get_posts filter you can make modifications to the query and change things like the number of posts, the post types, and other parameters.

You can read more in the docs

0

As the function file is load each time, you can decide to load different functions.PHP depending on user profil, id, to test your code. Create a new PHP file name it differently and include it at the end of the original functions.php like this i.e :

If(current_id()==1){include('function_dev.php');}

This will able you to change the behaviours of your theme, styling, support features, custom post type.... that can be load within this function file without editing of the original theme function file (it's fine when you have update, but it's better with child theme).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.