How to make WordPress functions file the functions.php

Hi, in this post the uses of functions.php file of WordPress theme development I am going to show you the uses of functions.php file of a WP theme. The functions.php file uses for defining all the function and hooks inside a WordPresst heme development. In this post I will teach about some basic function like how to define or include css or is files and how to make the theme thumbnail supported as well as woo-commerce supportable. And during the steps of the tutorial I will tell more about functions like how to define dynamic menu, sidebar, multiple sidebar or custom post or how to make a widget using function.php file.

For that

Step 1 . First create a functions.php file inside your theme folder

Step 2. Now open php tag

Step 3 . now start write the WordPress functions and hooks

Like Write the

  1. add_theme_support ( 'post-thumbnails' );

    for make the theme thumbnail supported

If you are not using the code then you cannot be able to add thumbnail or featured image inside your default post or pages

 

  1. Add the code.
     add_theme_support ( 'woocommerce' );

    To make the theme woocommerce supportable if you are not using the code then also your  will support woocommerce plugin but uses of the code is better.

 

  1. Use the belowcode to include the JavaScript library file
//to register any script in wordpress
if (!is_admin()):
add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
wp_deregister_script('jquery');
wp_register_script('jquery', "//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js", false, null);
wp_enqueue_script('jquery');
}
endif;
Theme function.php file of wordpress

Theme function.php file of wordpress

The portion of code wp_deregister_script(‘jquery’);  is for remove if already added the JavaScript library

And the portion of below code is for include the JavaScript library file.

wp_register_script(‘jquery’, “//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js”, false, null);

wp_enqueue_script(‘jquery’);

 

  1. Use the code below for include custom js and other library.

 

//to register any script in wordpress
if (!is_admin()):
add_action("wp_enqueue_scripts", "my_custom_jquery_enqueue", 11);
function my_custom_jquery_enqueue() {
wp_deregister_script('custom_js');
wp_register_script(‘custom_js', "//custom_js_link.js", false, null);
wp_enqueue_script(‘custom_js');
}
endif;

 

Change the key and link , here its jquery and //ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js and the name of the function

 

Please remove the js links from your theme HTML or twice inclusion will be closed of conflict of script as it will be included by WordPress function as you are defining to include the scripts.

 

In this post we have learned the uses of function.php file of a WordPress theme development.

Next we will learn how to make a theme options portion for a WordPress theme and get the values in front-end.

 

Thanks for reading

 

Share The Post On -

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.