Video: Configuring baseline settings and functions

Now that we have the theme info setup, it's time to start configuring the baseline settings and functions for our theme. Most of this work is done from the functions.php file, which, as the name suggests, contains the custom functions that control the theme. The default functions.php file for underscores is well built out and has most of the elements we want either activated or waiting to be activated. All we have to do right now is go in and make the changes we want.

Configuring baseline settings and functions

Now that we have the theme info setup, it's timeto start configuring the baseline settings and functions for our theme.Most of this work is done from the functions.php file, which,as the name suggests, contains the custom functions that control the theme.The default functions.php file for underscores is well built out and hasmost of the elements we want either activated or waiting to be activated.All we have to do right now is go in and make the changes we want.

So let me walk you through this file as Imake changes, starting at the top with this value called content_width.By setting the content width, you're tellingWordPress that if someone places content within thecontent area of a post or a page, it can never be wider than this amount.So if they grab a YouTube video or an image from Flickr,or something like that, this value will contain it within that set width.To figure out exactly what that width is, I have to go check out my design.So in my design I can measure the width ofmy contents, and here you see it's 600 pixels wide.

So then I can go and change this to 600 pixels, andnow, nothing will ever be above 600 pixels when it's inside the contents.Scrolling down, I have the my_simone_setup function andthis is the main function of the theme.Now you'll notice that the my_simone_setup function is wrapped in a conditionalstatement that says, if not functionexists, my_ simone_setup, then run the function.This is really important and this is what's called a pluggable function.Basically, if someone wants to make a child themebased on this theme, they can create a new function.phpfile and create a new function within that function.php filecalled my_simone_setup, and that function will automatically override R function.

Simply because when you use a child theme, the child theme functions.phpfile is called first and then the parent theme function.php file is called.So if you want people to be able to make child themes and you want them to be ableto disable some of your functions, you simply wrap themin this type of conditional statement and make them pluggable.Scrolling down, you'll see this is where most of our features are activated.Here you have the text domain feature, which allows translation.We also have theme support for automatic feed links so that defaultpolls and comments, RSS feeds link to the head of the page.

And then we have a commented out feature.Here we can enable support for post-thumbnails,or featured images if you want to.So here I'm going to remove the comment,so that post-thumbnails is activated, and later inthe course, we'll define the sizes of ourfeatured images and have them into our theme.Next, we have registered nav menus, which is where you define the custom menusfor the theme, and as you can see, we currently have one called Primary Menu.Then we have theme support for post formats, and here you seethe theme currently has support for asides, images, videos, quotes and links.

So I'm going to remove all but aside here.If you want to you can leave the ones that are there or you can add moreif you like, but I'm not a big fan of post formats, I'm just going to leave aside.Then we have the function that allows the user to define a custom background color.This is a core function in WordPress, but it's onethat I don't really like, so I'm actually going to deactivate it.And here I'm going to show you a little trick in NetBeans.If you want to comment out more than one line, youcan simply highlight it, and then hit control or command and forwardslash, and the application will automaticallycomment out all of those linesfor you, so you don't have to do them line by line.

Scrolling down I have support for HTML5 markup.Now this is cutting edge and like I said, when you're working with underscoresyou have the most recent and most up to date web standards in mind.So here we have HTML5 support for comment list,search-form, content-form, and gallery and I'm going to add onemore, so I'll add in caption so that mycaptions and my images are also wrapped in HTML5 tags.And as HTML5 progresses, I'm sure there willbe more features that will appear here as well.

The next function is called register_sidebar, and this iswhere you define the widgetized areas for the site.So right now we have one sidebar.It's in the side.And later on in the course we'll addan additional sidebar that will be in the footer.And you'll see what I mean when I saysidebar later on, but this is where it's defined.Then we have the enqueue scripts functions which allow usto enqueue styles and scripts so this is where our stylesheet is called, and also where our different JavaScripts are calledand we'll add more to this later on in the course.

And then at the bottom of functions.php we have a list of required template files.And here you see that we have a call to include template tags, include extra,include customizer, and include jetpack, which are olderfiles you will find under the include folder.There is also an optional one here.The top one, which implements to Custom Header feature.I want the Custom Header feature, because it allows touse it at a Custom Header image into the site.So I'm going to activate this feature.

Now before I save, let me just show you whatWordPress looked like before I made all of these changes.So I'm going to swap back to WordPress, here I am in admin, andyou'll remember I made a lot of changes to the appearance of the site.So right now you see when I hover overAppearance, we have Themes, Customize, Widgets, Menu, Background, and Editor.But you'll remember I've removed Background andthen I added the Custom Header feature instead.So if I go and save functions.php now with my changes, and then go and reload theadmin panel here and hover over Appearance again, you'llsee in place of Background, I now have Header.

This is just one example of the different things that we changed from functions.php.

There are currently no FAQs about WordPress: Building Themes from Scratch Using Underscores.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.

Already a member ?

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships.
Learn more

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.

Sign up and receive emails about lynda.com and our online training library:

new course releases

newsletter

general communications

special notices

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

new course releases

newsletter

general communications

special notices

Here’s our privacy policy with more details about how we handle your information.