If someone want to create a custom WordPress Theme then functions.php is the most important file. For creating a WordPress Theme, we have to at least some files listed below :
- style.css
- index.php
- functions.php
- header.php
- footer.php
- page.php
Above listed files are minimum requirement for and WordPress Custom Theme. Today I will show how to create a functions.php, how to enqueue Style Sheets(CSS) and JavaScript, adding featured image support, excerpt length change and so on….
Creating functions.php with Bootstrap 4 CDN files, also we will keep CSS and JavaScript file in footer, so as per google content will load first and then others files, it will also add some good reputation on search engine’s eye.
<?php //loading css files in footer add_action( 'get_footer', 'load_styles' ); function load_styles() { wp_enqueue_style( 'style', get_stylesheet_uri(), false ); wp_enqueue_style( 'bootstrap', "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css", false ); wp_enqueue_style( 'main', get_template_directory_uri()."/css/main.css", false ); } //loading Js file in footer also add_action('wp_enqueue_scripts','load_js'); function load_js(){ wp_register_script( 'Jquery','https://code.jquery.com/jquery-3.2.1.slim.min.js','','', true ); wp_register_script( 'Popper','https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js','','', true ); wp_register_script( 'Bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js','','', true ); wp_register_script( 'Main', get_template_directory_uri()."/js/main.js",'','', true ); wp_enqueue_script( 'Jquery' ); wp_enqueue_script( 'Popper' ); wp_enqueue_script( 'Bootstrap' ); wp_enqueue_script( 'Main' ); } //Feature image add_theme_support( 'post-thumbnails' ); //creating thumbnail footer-thumb size 64X64 add_image_size( 'footer-thumb', 64, 64, false ); //creating thumbnail thumb128 size 128X128 add_image_size( 'thumb128', 128, 128, false ); //Custom length excerpt function custom_excerpt_length( $length ) { return 40;//set custom value instead of 40 } function new_excerpt_more($more) { global $post; } add_filter('excerpt_more', 'new_excerpt_more'); add_filter( 'excerpt_length', 'custom_excerpt_length', 999 ); // Site Logo using Cutomizer add_action( 'customize_register', 'sp_customize_register' ); function sp_customize_register( $wp_customize ) { $wp_customize->add_section( 'sp_logo' , array( 'title' => __( 'Site Logo', 'sp' ), 'description' => 'Modify the site logo image' )); $wp_customize->add_setting( 'site_logo' , array( 'default' => '' )); $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'site_logo', array( 'label' => __( 'Upload Site Logo', 'sp' ), 'section' => 'sp_logo', 'settings' => 'site_logo' ) )); } ?>
Wow its working thanks
Welcome
Can We Talk For Sometime???
Email Me.
I have already mailed you details