New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Replacing existing functions

From: WordPress 3: Building Child Themes

Video: Replacing existing functions

From time to time you'll want to disable or replace existing functions altogether. This can be because you want to remove the function or because you want to replace it with something completely different. To get a clear picture of when this would happen, it's important to understand what types of functions you're likely to find in the functions.php file. In addition to the typical WordPress functions like the ones you have seen-- menus, sidebars, navigation, and so on-- the functions.php file also often carries with it calls to style sheets and JavaScript through what's known as enqueueing.

Replacing existing functions

From time to time you'll want to disable or replace existing functions altogether. This can be because you want to remove the function or because you want to replace it with something completely different. To get a clear picture of when this would happen, it's important to understand what types of functions you're likely to find in the functions.php file. In addition to the typical WordPress functions like the ones you have seen-- menus, sidebars, navigation, and so on-- the functions.php file also often carries with it calls to style sheets and JavaScript through what's known as enqueueing.

If you want to disable these, you need to dequeue them. If you look at the functions.php file from the parent theme, you'll see here on line 90 you have this function called twentytwelve_scripts_styles. Inside this function you have several scripts that are enqueued so that WordPress can use them. You see one here, wp_enqueue_script ( 'comment-reply' ), directly below it wp_enqueue_script( 'twentytwelve_ navigation, and this last one is the one the calls in the custom Opens Sans font from Google Fonts that was the default in the theme before we changed it.

So what does it mean when it says that a script or a style is enqueued? Well, it means that WordPress is calling it into the theme without specifying it in the header.php file or footer.php file or anywhere else. For example, we can see here that the style for this Open Sans font is being enqueued. But if you go into the header.php file, you won't find any reference to the style sheet for this Google font. However, when you load the page and then go look at the code behind the scenes, you'll see that here, on line 20, you have the style sheet directly from fonts.googleapis.com, which means the font is being called in, but it's being called in through the enqueue function.

That means this style and the other styles and the other JavaScript functions are being added through the functions.php file instead. And because they are added in through an enqueue function, we need use the dequeue function to take them out so that we can replace them. By dequeuing functions in your child theme, you're actively telling WordPress to ignore those functions after they've been called in the parent theme. It seems a bit convoluted and to be quite frank, it is quite convoluted, but it allows you to control functions without actually removing them from the parent theme altogether.

Show transcript

This video is part of

Image for WordPress 3: Building Child Themes
WordPress 3: Building Child Themes

45 video lessons · 32519 viewers

Morten Rand-Hendriksen
Author

 
Expand all | Collapse all
  1. 6m 59s
    1. Welcome
      1m 6s
    2. Using the exercise files
      1m 34s
    3. What you need to know before watching this course
      1m 29s
    4. Getting the right tools for theme creation
      2m 50s
  2. 17m 2s
    1. What is a WordPress child theme and when should you use it?
      2m 38s
    2. Picking a parent theme
      3m 55s
    3. Making sure you have the Twenty Twelve parent theme
      1m 50s
    4. Creating and activating a basic child theme
      4m 20s
    5. Importing parent theme styles
      4m 19s
  3. 16m 2s
    1. Using the developer tools
      3m 53s
    2. Modifying existing styles
      4m 24s
    3. Adding space between paragraphs
      4m 7s
    4. Changing font family styles
      3m 38s
  4. 31m 47s
    1. Understanding the WordPress template hierarchy
      3m 12s
    2. Modifying existing templates
      2m 33s
    3. Moving the header image
      4m 29s
    4. Adding Related Posts feature to posts
      6m 26s
    5. Creating custom page templates
      5m 43s
    6. Using conditional statements for customized effects
      5m 41s
    7. Creating custom header, footer, and sidebar templates
      3m 43s
  5. 17m 5s
    1. Understanding the different index pages and what they do
      4m 6s
    2. Adding author, date, and time information to the index loop
      7m 15s
    3. Changing the appearance of category index pages
      5m 44s
  6. 43m 5s
    1. Introducing functions.php
      3m 24s
    2. Overriding existing functions
      3m 23s
    3. Adding pagination to index pages
      5m 49s
    4. Adding to existing functions
      3m 21s
    5. Adding a new footer menu to Twenty Twelve
      6m 24s
    6. Adding a new widgetized area to pages
      4m 9s
    7. Adding static content to the sidebar
      7m 44s
    8. Replacing existing functions
      2m 36s
    9. Adding a Google font through a function
      6m 15s
  7. 10m 24s
    1. Adding new featured image sizes
      5m 41s
    2. Adding featured images to posts and pages
      4m 43s
  8. 31m 1s
    1. Adding a welcome message to the front page
      1m 22s
    2. Displaying page content in an index page
      7m 42s
    3. Hooking in a featured image
      4m 34s
    4. Making the welcome message responsive
      6m 27s
    5. Restricting content to the first page of the blog
      4m 22s
    6. Adding a jQuery function to show or hide the welcome message
      6m 34s
  9. 10m 23s
    1. Adding a custom favicon
      3m 58s
    2. Adding a custom screenshot
      2m 29s
    3. Adding footer information
      3m 56s
  10. 7m 14s
    1. What to do when a child theme crashes your website
      4m 38s
    2. Updating parent and child themes
      2m 36s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold

Are you sure you want to delete this note?

No

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:

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:

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

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.