Support » Fixing WordPress » code in theme / code in child-theme

Viewing 2 replies - 1 through 2 (of 2 total)
  • Josh

    (@josh401)

    Okay…

    There are two common uses of a child theme:

    1. To modify CSS:

    a. You create a child theme folder, and place a file named style.css. In that file, you import the main themes stylesheet. From there, you can add css rules which ‘modify’ the themes stylesheet.

    b. The theme’s stylesheet loads first.. then the child theme stylesheet will load… so the child stylesheet ‘overwrites’ any of the rules from the main theme stylesheet.

    c. This is because CSS works from top to bottom (it takes Precedence). If you define an <a> tags styles in the first line of the main theme stylesheet.. then define them again somewhere in the child theme stylesheet.. the browser will load the LAST item defined if they have the same name.

    2. For adding or modifying functions:

    a. This is done by adding a functions.php file to the child theme. You don’t have to “import” anything from the main theme. There are basically two cases here:

    i. To add new functions. You can simply create any function.. and run it from this file.

    ii. To modify (or hook, or filter) the parent theme functions. WP uses many hooks and filters… which you can use in your php files.

    3. To ‘replace’ a part of the parent theme funtionality. This is what you are doing now.

    a. If you take the header.php file from the parent theme… and place it into your child theme… WP will load that file from your child theme and not from the parent theme. So.. you can modify that file to your liking.. and place it in your child theme… and it gets rendered from there in the browser.

    This has both advantages and disadvantages. A good thing is that you can add custom code.. while still preserving the other functionality of the main theme. A downside is if the parent theme radically replaces that file in an update… you may not get all of the added features.

    So.. it really comes down to specific use-case scenarios.. of how you would want to make your modifications.

    Hope this helps.

    To answer your question… the VERY FIRST page that the browser loads is the index.php file found in the root of your WP install folder 😉

    Thread Starter NollieHeel

    (@nollieheel)

    Thanks for all that info. I hope others in the future find this post as well.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘code in theme / code in child-theme’ is closed to new replies.