• I’m not very clever at this but I have followed all the advice about creating a child folder to make changes to style.css, functions.php, and single.php, within the twentyeleven style folder. Works nicely (www.evamusby.co.uk)

    There are other changes I’ve made, for instance I’ve changed wp-includes/comment-template.php to change the look of the comments boxes.
    But when the TwentyEleven theme next gets updated, will I lose these changes? If so, could a kind soul tell me what files to create where?
    Thanks!
    Eva

Viewing 8 replies - 1 through 8 (of 8 total)
  • Never, ever, edit core WordPress files! You need to make all of the necessary changes in your child theme.

    Thread Starter evamusby

    (@evamusby)

    Ah, OK, thanks.
    So could anyone advise me how to make changes using a child folder in this situation?
    For example I want to change stuff that’s presently in wp-includes/comment-template.php . I take it I create a new file comment-template.php with the changes in it? And I put that file where? Anything else that I need to do so that file gets put to work?

    Just so you know what (poor) level of knowledge I have, at present I have a folder I called “mine-tewentyeleven-child” and it’s in the wp-content/themes folder, and it contains a modified style.css, a single.php, and a functions.php, each containing my changes. Where I’m stuck is what happens when the file I want to change is in the wp-includes folder.

    By the way, I am bowled over by wordpress, what it does, and that it’s the result of so much generosity from people.
    Eva

    I want to change stuff that’s presently in wp-includes/comment-template.php

    Start by reviewing comment_form() and wp_list_comments(). You may need to make your changes via a custom comments.php template file or functions.php file in your child theme.

    Thread Starter evamusby

    (@evamusby)

    Thank you Esmi. See these pages you are suggesting I look at? I would love to understand them, because so far I haven’t used anything like this and it’s getting me stuck.

    So I have one question which may, by example, help me understand how all this works.
    See in that comment-form()page you’ve linked to, there’s this:

    comment_field
    (string) (optional) The textarea and the label of comment body.
    Default:
    ‘<p class=”comment-form-comment”><label for=”comment”>’ . _x( ‘Comment’, ‘noun’ ) . ‘</label><textarea id=”comment” name=”comment” cols=”45″ rows=”8″ aria-required=”true”></textarea></p>’

    Say I want to change the default “Comment” to “Reply” then can you tell me where/how I do this?
    As I said earlier, the way I’ve done it up to now is found a line [saying ‘comment_field’=> ‘<p class etc etc ] in file comment-template.php inside the wp-includes folder and that’s what I’ve been naively editing.

    I’m hoping if I understand this I’ll understand loads of other similar things, so thanks for any help. (And I’m afraid I don’t understand what you mean by “You may need to make your changes via a custom comments.php template file or functions.php file in your child theme.” Though I do have a functions.php file in a child folder I created within wp-content/themes)
    Thanks
    Eva

    The easiest way to explain this is for you download a copy of the ZenLite theme and then examine its comments.php and functions.php files.

    Thread Starter evamusby

    (@evamusby)

    Thanks, I’ll give it a try, though I suspect I’m missing some more fundamental thing about HOW to change the bits I want to change. Bedtime for me now though.
    Thanks you again

    Thread Starter evamusby

    (@evamusby)

    I hope this is OK with everyone. I have searched quite a bit on the forum and realise there are plenty of people like me who have become frustrated at this level. They get referred to the codex for function parameters and it means nothing to them. They find help on creating a child theme but not on how to use it. I found some bits of answers here and there and have pieced it all together to help others who are at my rather ignorant level.

    If anyone finds I’ve done something unorthodox, please chip in.
    I’ve put all this in action, with slightly different words, on https://www.evamusby.co.uk
    Here goes:

    Say I’m wanting to change a bit in the Comments area, where the user is asked for their email. I search everywhere for the words ‘Email’, or “Leave a Reply” and find that these and all the other comments form stuff is in folder “wp-includes”, in file “comment-template.php”
    Notice that the stuff I want to change (e.g. the word “Email”) is within a function in this file, it’s written: “function comment_form”.

    Note: Search the www.remarpro.com Codex for comment-form: there’s a page explaining the various parameters, and for people like me it takes a while to understand, which is why I’m making my own notes of what to do next.

    Now I search in folder “wp-content/themes/twentyeleven” (because the theme I use is twentyeleven) for a file that calls up this function, i.e. search for the word “comment_form”.

    A good place to look for might be in “functions.php”, but instead I find it here: in file “wp-content/themes/twentyeleven/comments.php”. It’s at the bottom, in this line:
    <?php comment_form(); ?>

    This is the bit to modify, but don’t modify it here, or it will be lost at the next theme update. Instead, modify it in a child folder as follows.

    Create a child folder inside the themes folder :” wp-content/themes/my-child” You can name it whatever you like, but in this example it’s named “my-child”.
    Inside this child folder, create a file named “comments.php” . This is the one to work on.

    Type the first few lines in the file like this:

    <?php
    /* These are my notes on how I changed the comment form.
    I am quite a beginner but I hope this will help other beginners.
    */
    ?>

    Next, here’s how I changed various parts of the comment form:

    <!—Here are some of my changes.
    This is to change what the visitor sees in the comment form area: the instruction (for author, email, url, comment field) and in some cases, the size of the text box
    –>
    <?php $comment_args = array( ‘fields’ => apply_filters( ‘comment_form_default_fields’, array(

    ‘author’ => ‘<p class=”comment-form-author”>’ . ‘<label for=”author”>’ . __( ‘Please type in your name’ ) . ‘</label> ‘ . ( $req ? ‘<span class=”required”>*</span>’ : ” ) .
    ‘<input id=”author” name=”author” type=”text” value=”‘ . esc_attr( $commenter[‘comment_author’] ) . ‘” size=”130″‘ . $aria_req . ‘ /></p>’,

    ’email’ => ‘<p class=”comment-form-email”><label for=”email”>’ . __( ‘Please type in your mail (it won\’t be displayed)’ ) . ‘</label> ‘ . ( $req ? ‘<span class=”required”>*</span>’ : ” ) .
    ‘<input id=”email” name=”email” type=”text” value=”‘ . esc_attr( $commenter[‘comment_author_email’] ) . ‘” size=”30″‘ . $aria_req . ‘ /></p>’,

    ‘url’ => ‘<p class=”comment-form-url”><label for=”url”>’ . __( ‘Please type in your website’ ) . ‘</label>’ .
    ‘<input id=”url” name=”url” type=”text” value=”‘ . esc_attr( $commenter[‘comment_author_url’] ) . ‘” size=”30″ /></p>’,

    //Note the two brackets and the comma here

    ) ),
    //Now I can change some of the other things in the form. Note that here I can change the number of columns too, in other words how large the box is

    ‘comment_field’ => ‘<p class=”comment-form-comment”><label for=”comment”>’ . _x( ‘ Go on, write a comment’, ‘noun’ ) . ‘</label><textarea id=”comment” name=”comment” cols=”45″ rows=”8″ aria-required=”true”></textarea></p>’,

    //The following shows how I can put a link in too

    ‘comment_notes_before’ => ‘<p class=”comment-notes”>’ . __( ‘Check out my comments policy here.’ ) . ( $req ? $required_text : ” ) . ‘</p>’,

    //Note the bracket and the comma here, right at the end

    );
    comment_form($comment_args); ?>

    And that’s the last line. I hope the above works for you.
    Note that if you want to remove parts of what normally appears, for instance to remove the bit that asks a user for their website: you’d replace what I put earlier in the line starting ‘url’ => ‘lots of stuff here'</p>, and replace it with

    ‘url’ => ”,

    Thread Starter evamusby

    (@evamusby)

    Addition to the above.
    I’m doing things by trial and error, so apologies. With the above, people’s comments were not displayed.
    I fixed that by copying the following lines from file ‘comments.php’ which is in folder themes>twentyeleven:
    I copied from:
    <?php if ( have_comments() ) : ?>
    <h2 id=”comments-title”>
    to:
    <p class=”nocomments”><?php _e( ‘Comments are closed.’, ‘twentyeleven’ ); ?></p>
    <?php endif; ?>
    I pasted this in the ‘comments.php’ file of my child folder. I pasted it just before the line I told you to put in, that starts:
    <!—Here are some of my changes.

    I’m sorry I hardly know what I’m doing, but it works, and as it looks like others have been hunting without success, I hope it helps someone.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Changing php files in wp-includes: do I need a child folder?’ is closed to new replies.