Start learning with our library of video tutorials taught by experts. Get started
Viewed by members. in countries. members currently watching.
Create a child theme based on an existing parent theme in WordPress and change the functionality, presentation, or styling of your website. In this course, author Morten Rand-Hendriksen shows how to use the default WordPress theme, Twenty Twelve, as a basis for a new child theme and add custom menus; new headers, sidebars, and footers; and index pages with widgets and pagination to your site. The course also demonstrates how to add a responsive welcome message to your front page using PHP and jQuery, and how to edit the many templates found in a WordPress theme. Morten explains how to perform these changes using any code editor, the developer tools in the Chrome browser, and WordPress.
One of the first things people want to do when they activate a new WordPress theme is make changes to the look and feel of the theme to make it their own. This usually means making changes to the theme styles. Child themes were introduced to make this process non-destructive, meaning you don't have to mess with the core or parents theme styles to get what you want. That way you won't inadvertently break the parent theme and your changes won't be overwritten in the future when the parent theme updates. Let's take a look at how you go about making changes to the styles on your website using your child theme.
If you look closely at the images in the Twenty Twelve theme, you'll notice that they have a slight drop shadow behind them and that the box that contains them has rounded corners. You see the shadow here behind this white image and if we scroll down, you see that this solid image has rounded corners. If you want to change that, you have to make changes to the style sheet and those styles are in the parent theme. So what we're going to do is to use our child theme styles to override the parent theme styles. This is because of how CSS works.
CSS or cascading style sheets work on the simple principle of a cascade. The first styles that are listed have less importance than the last ones, meaning the ones that are the furthest down in the stylesheet matter the most. In the case of a child theme, the parent theme is called first and then the child theme. So any style that's in the child theme stylesheet has more importance than the ones that are in the parent stylesheet. If I use the developer tools here I can right- click on the image, click Inspect element and here I can see the styles that affect the image. You see the first style is this image align right, but this style only affects alignments.
If I scroll down you see that the second style here, the one that affects entry content image and other images has two variables; border-radius, and box -shadow, and obviously, these are impacting the image. If I want to see if this is a style I want to change, all I have to do is turn one of those styles off, so I'll turn off box- shadow, and now you see the box-shadow disappears. That also makes it harder to see the rounded corners though, because there's a white background and this image has a white background as well, so I'll scroll down and find another image, and here you see it still has a rounded corner, and I can now change that rounded corner radius either by going in and saying, let's say 10 pixels, to get a much more rounded corner, or I can go out and knock it away altogether and get a square corner.
Now that I know that I want to change the style, the next step is a copy to style itself, or copy the whole style and then go to my stylesheet in my child theme. So I'll navigate to my child theme, and open style.css in my text editor, and here I'm simply going to paste in the original style the way it was written. So here we have the style copied straight out of the browser. You see I made a change to it, I made border radius 10 pixels, but since I want to get rid of the border radius, I am going to set it to 0 instead, and then I'm also going to change box-shadow from these values to none, just to clean up a bit of code here so it's looks nice. And now when I save the stylesheet in the child theme, I can go back to my browser, reload the page, and you see that my changes are taking effect, and now I have square corners and no drop shadow.
But this isn't style that I changed in the parent stylesheet. I changed it in the child theme stylesheet, meaning I can now go back to the child theme stylesheet and simply comment out my new style, save it, reload the page and the old styles from the parent stylesheet kick back in. So now you see the power of a child theme style sheets. Instead of having to go and muck around with the actual styles and risk breaking something, you're simply adding on new styles and seeing what they do. And this doesn't just apply to styles you want to change, you can also go into your child theme and just add new styles at will.
So if you have new content then you need to change the way that appears, you can simply add new styles here and they'll be appended to the original styles from the parent theme. That way you're building on top of the parent theme instead of building everything from scratch. By modifying or overriding styles with your child theme, you can make quick and easy changes to your theme without having to touch the theme itself, and if you don't like what you did you just go back in and take out that new style code and you are back where you started.
Find answers to the most frequently asked questions about WordPress 3: Building Child Themes.
Here are the FAQs that matched your search "":
Sorry, there are no matches for your search ""—to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.