How to Add Functionality with functions.php

Heads up: The following fix requires that you basically kill your dev site. If you still want to have a dev or staging site, pick a different subdomain and put it there. Then follow the instructions here to make sure this doesn’t happen again.Heads up: The following fix requires that you basically kill your dev site. If you still want to have a dev or staging site, pick a different subdomain and put it there. Then follow the instructions here to make sure this doesn’t happen again.

The functions.php file is the “brain” of a WordPress theme. It’s where we add all kinds of presentational functionality—PHP functions that control how things display, rather than the site’s underlying data—for the theme.

In this tutorial, we’ll cover how to work with the functions.php file, and some of what it can do for your theme and site.

// Add theme support for featured images, and add a few custom image sizes
add_theme_support( 'post-thumbnails' ); 
add_image_size( 'featured-image-large', 640, 294, true );
add_image_size( 'featured-image-small', 200, 129, true );
add_image_size( 'featured-image-tiny', 124, 80, true );

// Enqueue theme JavaScripts and CSS styles
function wpshout_scripts( ) {
    // Enqueue JS that gives the search box a default value
    wp_enqueue_script( 
        'search-box-value',
        get_stylesheet_directory_uri() . '/js/search-box-value.js',
        array( 'jquery' )
    );

    // Enqueue JS that sets a dynamic page minimum height
    wp_enqueue_script( 
        'page-min-height',
        get_stylesheet_directory_uri() . '/js/page-min-height.js',
        array( 'jquery' )
    );

    // Enqueue main theme stylesheet
    wp_enqueue_style( 
        'wpshout-style',
        get_stylesheet_uri()
    );
}
add_action( 'wp_enqueue_scripts', 'wpshout_scripts' );

// Register main navigation menu
function wpshout_register_menu( ) {
    register_nav_menu( 'main-nav', 'Main Nav' );
}
add_action( 'init', 'wpshout_register_menu' );

About Bas Martens

Bas MartensLorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc imperdiet rhoncus arcu non aliquet. Sed tempor mauris a purus porttitor, ac convallis arcu venenatis. Donec lorem erat, ornare in augue at, pharetra cursus mauris.

Leave a Comment

Thank you for leaving a comment. All comments are moderated according to our comment policy. Keep comments in english please. We will never publish your email address.