Add Theme Support – WordPress Snippet Generator

This tool is intended to speed up, simplify, and standardize the production of code snippets to add theme support. Please scroll past the tool to learn more about how to correctly fill out the forms and implement the code.

  • General
  • Images
  • Translation
  • Post Formats
  • HTML5
  • Code

General

Item
Input

Quick Options

Item
Input

Content Width

Item
Input

Post Thumbnails

Item
Input

Custom Logo

Item
Input

Custom Background

Item
Input

Custom Header

Item
Input

Translations

Item
Input

Post Formats

Item
Input

HTML5

Item
Input

Copy Code

Your customized theme support code snippet is below. Be sure to fully read the instructions that follow before adding this code to your WordPress theme.

Registers Support For Theme Features

Add this code to your functions.php file. Scroll down to learn more.

      


add_action( 'after_setup_theme', '{{themeSlug || 'your_theme_slug'}}_setup' );

// Registers Support For Theme Features
function {{themeSlug || 'your_theme_slug'}}_setup()  {

        // Declare globals.
        global $content_width;


	// Add default posts and comments RSS feed links to head
	add_theme_support( 'automatic-feed-links' );


	// Post Format support.
	add_theme_support( 'post-formats', array( 'status','quote','gallery','image','video','audio','link','aside','chat' ) );


	// This theme uses post thumbnails
	add_theme_support( 'post-thumbnails' );


	// Set custom thumbnail dimensions
	set_post_thumbnail_size( {{setPostThumbnailSizeWidth || '50'}}, {{setPostThumbnailSizeHeight || '50'}}, true );


        // Add theme support for a custom logo.
        add_theme_support( 'custom-logo', array(
                'height'      => 100,
                'width'       => 400,
                'flex-height' => true,
                'flex-width'  => true,
        ));


	// Add theme support for Custom Background
        ${{themeSlug || 'your_theme_slug'}}_background_args = array(
                'default-image' => '{{customBackgroundDefaultImage}}',
                'default-preset' => '{{customBackgroundDefaultPreset || 'default'}}',
                'default-position-x' => '{{customBackgroundDefaultPositionX || 'left'}}',
                'default-position-y' => '{{customBackgroundDefaultPositionY || 'top'}}',
                'default-size' => '{{customBackgroundDefaultSize || 'auto'}}',
                'default-repeat' => '{{customBackgroundDefaultRepeat || 'repeat'}}',
                'default-attachment' => '{{customBackgroundDefaultAttachment || 'scroll'}}',
                'default-color' => '{{customBackgroundDefaultColor}}',
                'wp-head-callback' => '{{customBackgroundWpHeadCallback}}',
                'admin-head-callback' => '{{customBackgroundAdminHeadCallback}}',
                'admin-preview-callback' => '{{customBackgroundAdminPreviewCallback}}',
        );
        add_theme_support( 'custom-background', ${{themeSlug || 'your_theme_slug'}}_background_args );


	// Add theme support for Custom Header
        ${{themeSlug || 'your_theme_slug'}}_header_args = array(
                'default-image' => '{{customHeaderDefaultImage}}',
                'random-default' => {{customHeaderRandomDefault || 'false'}},
                'width' => {{customHeaderWidth || '0'}},
                'height' => {{customHeaderHeight || '0'}},
                'flex-height' => {{customHeaderFlexHeight || 'false'}},
                'flex-width' => {{customHeaderFlexWidth || 'false'}},
                'default-text-color' => '{{customHeaderDefaultTextColor}}',
                'header-text' => {{customHeaderHeaderText || 'true'}},
                'uploads' => {{customHeaderUploads || 'true'}},
                'wp-head-callback' => '{{customHeaderWpHeadCallback}}',
                'admin-head-callback' => '{{customHeaderAdminHeadCallback}}',
                'admin-preview-callback' => '{{customHeaderAdminPreviewCallback}}',
                'video' => {{customHeaderVideo || 'false'}},
                'video-active-callback' => '{{customHeaderVideoActiveCallback || 'is_front_page'}}',
        );
        add_theme_support( 'custom-header', ${{themeSlug || 'your_theme_slug'}}_header_args );


        // Add theme support for HTML5 semantic markup.
        add_theme_support( 'html5', array( 'comment-list','comment-form','search-form','gallery','caption' ) );


        // Add theme support for document Title tag
        add_theme_support( 'title-tag' );


        // This theme styles the visual editor with editor-style.css to match the theme style.
        add_editor_style();


        // Make theme available for translation
        // Translation files should be located in the /{{translationLoadThemeTextdomainDir || 'language'}}/ directory
        load_theme_textdomain( '{{textDomain || 'your-text-domain'}}', get_template_directory() . '/{{translationLoadThemeTextdomainDir || 'language'}}' );


        // Set content width based on the theme's content column width.
        if (!isset($content_width)) {
                $content_width = {{contentWidthWidth || '1168'}};
        }
 
}
    
    

Instead of wading through lines of code when activating optional WordPress core functions like translation, custom backgrounds and logos, HTML5 integration, or post thumbnails, we’ve put together this handy add_theme_support WordPress snippet generator to do the heavy lifting for you.

To use the tool, simply click “Support” on the feature you’d like activated, then fill out the relevant fields below the box to further customize the feature, when modifiers are available. When you’ve added everything you’d like, copy the code and paste it into the functions.php file. That’s all there is to it!

Let’s dig into the add_theme_support function to get a sense of what you can do with this powerful code resource.

What does “add theme support” mean?

When you build out a theme, there many core WordPress functions that you can choose whether or not to opt into. Sometimes you may not want to include all the functions, as they may not be compatible with an older theme, or you just don’t need the feature. By using the add_theme_support feature, you are choosing to register specific WordPress core functions so they display in the user admin interface. In plain English, it’s a way of declaring, “This is my theme, and I want to use ____ feature and ____ feature.” That’s the gist of the add_theme_support feature.

As an example, one of the features available through the add_theme_support function is translation. In the particular declaration, you add theme support for translation functionality and then declare your text-domain and the location of the directory where the translation files should reside. If you don’t include these attributes, WordPress won’t try to find anything translatable about the theme.

You will find that there are many enhanced customization options available for each of these features, which can be called up using the default arguments. I’ve included all possible options for each theme support feature, and by clicking “Support” in the snippet generator, these options will appear. The code will populate and build on itself as you click through the options and enter your modifiers.

Register Theme Support Features

Here’s a list of WordPress support features that you can register by using the add_theme_support feature. You will see all of these listed as elements that can be activated in the theme support snippet generator tool tabs above:

List of Available Features

  • Post Formats: This allows post formats to be incorporated into your theme and includes aside, gallery, link, image, quote, status, video, audio, and chat. If you are including this as part of a child theme, this will override parent theme formatting.
  • Post Thumbnails: These are the featured images for a post or page and can be displayed throughout the site in a variety of manners using the post thumbnail option. Note that, in the snippet generator above, you can choose which dimensions you want the post thumbnails displayed at as well.
  • Custom Background: This feature allows for inclusion of custom backgrounds. You can also choose to include default arrays – see here for the full list of custom background options, all of which can be included by clicking the “Support” option in the snippet generator.
  • Custom Header: Allows custom headers. Here’s the full list of header arrays you can customize via the snippet generator.
  • Custom Logo: Enables users to upload a custom logo. Click here for additional argument options. By clicking “Support” in the generator, you will find the rest of the attributes available for modification.
  • Feed Links: This option activates Automatic Feed Links so they can be used for RSS feeds for posts and comments in the <head>.
  • HTML5: This feature enables HTML5 markup for the comment list, comment form, search form, gallery and caption.
  • Title Tag: Adding this feature lets the theme control the title-tag.
  • Customize Selective Refresh Widgets: You can opt to selectively refresh widgets instead of having to refresh the entire page when working with the Customizer.

About the code output and adding to theme

When you output the code, you will want to paste it into your functions.php file. We always recommend to be sure to backup your site and use FTP so that in case there’s an error, you can fix it quickly with the old file.

Conclusion

We hope this tool helps condense the time spent on adding these integral WordPress theme support features into your functions.php file.


Written exclusively for

Nimbus Themes Publishing Logo

About the Author

Evan Scoboria is the co-founder, and developer at Shea Media LLC, the team behind Nimbus Themes, this magazine, and a bunch of very happy clients. He co-founded Shea Media with his wife Kendall in 2009. Evan enjoys hunting, fishing, code, cycling, and most of all WordPress!

Read all posts

3 Comments

  1. choupd Avatar

    choupd

    March 24, 2017 at 10:43 am

    hi, I can’t find the custom logo section in your wordpress snippet generator. could you tell me where to find it?

    Reply
    • Evan Scoboria Avatar

      Evan Scoboria

      March 26, 2017 at 12:53 pm

      Hello, Thank you for catching this. 🙂

      I see exactly what you’re describing and I’ll work on a solution over the coming day or two.

      Reply
    • Evan Scoboria Avatar

      Evan Scoboria

      March 27, 2017 at 10:25 am

      Okay, support for custom logos is added. Thanks again for catching that.

      Reply

Leave a Reply

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