• Resolved ejm

    (@llizard)


    Over the past few months, I have asked a number of questions about how to encode a child’s functions file and am quite disheartened at the lack of replies. I do understand that this is a forum peopled by volunteers. But surely there are people out there who do indeed understand how to encode functions files.

    I cannot believe that I am the only person interested to learn this without having to take an advanced course in PHP.

    Child themes are the recommended way of modifying an existing theme. […] [T]he functions.php of a child theme provides a smart, trouble-free method of modifying the functionality of a parent theme. (codex.wordpress.org/Child_Themes)

    The codex is not particularly helpful after that, especially with its really very poor example of how to encode a functions file. The example of coding // Do something. is particularly demoralizing and unhelpful.

    Creating a child theme when performing adjustments to your theme’s code can save you a lot of future headache. Child themes allow you to make changes without affecting the original theme’s code, which makes it easy to update your parent theme without erasing your changes. (elegantthemes.com | How To Create A Child Theme, And Why You Should Be Using One)

    Because I know only enough about php to get myself in trouble, I would like to have my child theme be made up of the stylesheet, functions file and only one or two other files – so that I do not have to update every file, every time that the parent theme is updated.

    Could someone please update the codex to give a few real-world examples of how to make minor customizations of a parent theme?

    Thank you.

    E. Morris, [Signature moderated]

Viewing 15 replies - 1 through 15 (of 17 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Lizard:

    I have a number of child themes (specifically for twentytwelve) that consist only of style.css, functions.php, header.php and footer.php.

    You wrote:

    I would like to have my child theme be made up of the stylesheet, functions file and only one or two other files – so that I do not have to update every file, every time that the parent theme is updated.

    There’s no need to copy/modify any files that are OK in the parent.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    If I could be bothered and if I had more time, I’d argue to take out the php stuff from creating a Child Theme. It’s not actually necessary to create a functions.php file. I’d go back to encouraging people to do the @import rule in the style.css file. Sure it’s good practice to be safe, but it bloats the process of creating a child theme, especially for someone who doesn’t want to make PHP modifications.

    That said, I’m not directing this at anyone. I cannot. The Codex isn’t managed by one person or a team of people. It is managed by you, me and anyone who wants to edit it.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    I do understand that this is a forum peopled by volunteers. But surely there are people out there who do indeed understand how to encode functions files.

    Sorry, but it seems as though you don’t understand what it means to have volunteer-driven support. It doesn’t really make sense to question it. For example if I were to ask you, why haven’t you been answering people’s threads?

    Thread Starter ejm

    (@llizard)

    Thank you for your responses.

    Steven, for the most part, my child theme of 2012 is working. There are just a few customizations that I am trying to understand how to make. Any forum questions along the same lines invariably recommend downloading and copying the parent file and changing it, rather than making the change in the functions file.

    I were to ask you, why haven’t you been answering people’s threads?

    Andrew, this is a fair enough question. My answer is that it would be a little like the blind leading the blind. However, I will attempt to answer the questions for which I do know the answers.

    I’d go back to encouraging people to do the @import rule in the style.css file.

    Alas, this does not address changes in text or addition of missing title specs to anchor links. If I ever do learn how to do this, I’ll attempt to add something to the codex – even though my grasp of coding is hardly in the league of most of the people who are editing those files.

    E Morris

    Thread Starter ejm

    (@llizard)

    There’s no need to copy/modify any files that are OK in the parent.

    Yes, Steven, that I do understand. However, let’s say that I copy 2012’s content.php for my child theme. That means that every time 2012 is updated, I have to re-copy content.php and make the changes again, does it not? If the changes are housed in the functions file, then there will be no need to make any re-modifications.

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    if you can get away with using filters to change the content produced in content.php then all is good. But yes, there are some costs related to child themes. I’ve had only one change to 2012 that broke stuff (in the header, the responsive menu changed from <h3 … stuff> to <button … stuff>, and that stopped the “menu” button from working.

    It’s never going to be perfect.

    Thread Starter ejm

    (@llizard)

    It’s the filters part and how to implement them that I’m trying to understand and having difficulty grasping. I don’t know enough about it to know what search words to use to find the answer. (When I do search, I invariably find my own unanswered questions….)

    Specifically, I’d like to learn more about how to insert some text before or after a specific place in one of the twentytwelve files. Can you recommend an online tutorial that addresses creating filters?

    for te customization of a child theme, there are limits on what can be done with functions.php;

    you can mainly only influence any functions which are either pluggable, or apply a filter to the output, or a done via action hooks.

    you can generally not change template parts or templates via the functions.php

    as using functions.php is in some aspects similar to using a plugin, possibly also review https://codex.wordpress.org/Plugin_API

    Thread Starter ejm

    (@llizard)

    Thank you, alchymyth.

    I have seen a number of references to “action hooks” but have yet to find a dummy’s style tutorial so I (a non-programmer) can grasp how to use them. What search terms should I be trying?

    Specifically, I’d like to learn how to get a filter and/or function to appear after (or before) something that is there.

    how to get a filter and/or function to appear after (or before) something that is there.

    that is not how it works.
    you need to look into the (php) source code of whatever template file or function you are trying to change (and also into whatever functions are called from within that section), to see if there is an ‘apply_filters()‘ code somewhere – then you can use ‘add_filter()‘ or ‘remove_filter()‘ to influence the output.

    similar with ‘do_action()‘ in some codes; if you find a ‘do_action()‘ somewhere in your theme, then you can use ‘add_action()‘ or ‘remove_action()‘ to influence the output.

    example from footer.php of the default theme Twenty Fifteen:

    do_action( 'twentyfifteen_credits' );

    the theme actually does not use add_action( ' twentyfifteen_credits', 'whateverfunction' ) in its files; this is just a hook for the creator of a child theme, to add credits via some code in functions.php of the child theme or via a plugin …

    David_G

    (@questas_admin)

    I cannot believe that I am the only person interested to learn this without having to take an advanced course in PHP.

    Maybe it’s time, this site has a free and easy to understand step by step course on php. Work at your own pace but it will help with understanding how to use php.
    https://www.codecademy.com/learn

    Thread Starter ejm

    (@llizard)

    Thank you for the link, questas_admin. I hope that it will cover filters, functions, actions and/or hooks.

    Also, thank you alcymyth. I will stare more at the twentytwelve files.

    David_G

    (@questas_admin)

    Yes, it starts at the very beginning, then works up from there. A very good course.

    Thread Starter ejm

    (@llizard)

    It would be great if it actually ran at a reasonable pace. I didn’t mind (very much) reviewing the absolute “hello world” basics but as soon as it got into a section that is relatively new to me (loops), the page either crashed or refused to load the example – and I don’t think it was because of the answers I was giving.

    I tried again this morning and it’s just as slow. Too bad.

    Thread Starter ejm

    (@llizard)

    you need to look into the (php) source code of whatever template file or function you are trying to change

    What I’m trying to do, Alcymyth, is add title specs to previous_post_link() and next_post_link(). I have gotten as far as seeing that these are housed in wp-includes/link-template.php and am guessing that I have to change $string somehow.

    This is my guess at what is necessary to change the string:

    $string = '<a href="' . get_permalink( $post ) . '" title=".$title.' rel="'.$rel.'">';

    Staring more at link-template.php, I see /** This filter is documented in wp-includes/post-template.php */ Does this mean that I want to use function or filter in my child functions file? AND ft’s function, which function(s)?

    Thank you for any help you can offer.

Viewing 15 replies - 1 through 15 (of 17 total)

The topic ‘frustrations with child functions file’ is closed to new replies.