Support » Fixing WordPress » Editing functions.php using wordpress codex. how to do the basics?

  • Hi,

    I am fairly new to wordpress, and have not developed before with php. I have been trying to make some basic customizations to my initial wordpress site (current theme: twenty sixteen). I am trying to understand how to do this. I think a lot of what I want to do can be found in the wordpress codex, but how do I enter the code changes I get from the codex?

    Here are some details:

    For example, I want to change the label on the submit a comment button from “Post Comment” to, say. “Have Your Say.” In looking online, folks point to the wordpress codex about the comment form: https://codex.wordpress.org/Function_Reference/comment_form.

    This has descriptions and sample code for doing this kind of thing, I think. It does not say where to enter the changes you want, but I assume it is in the functions.php file. But when I enter the code changes in the functions.php file, nothing changes.

    So, following the codex, to change the comment submit button, I believe this would be the code:

    $comments_args = array(
            'label_submit'=>'Have Your Say',
    );
    
    comment_form($comments_args);

    I plop this in my functions.php, and nothing changes. The comment form still says “Post Comment”. What am I missing?

    In case relevant: I am using twenty sixteen theme, and comment form is from default comment form (not jetpack–I disabled that on comments for some other stuff I was doing).

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Normally the functions.php file is the place to go to change core stuff about your theme, but in this case you may want to search your ‘comments.php’ file. Around line 73 you will find:

    comment_form( array(
        'title_reply_before' => '<h2 id="reply-title" class="comment-reply-title">',
        'title_reply_after'  => '</h2>',
    ) );

    just add your code so it looks like this:

    comment_form( array(
        'title_reply_before' => '<h2 id="reply-title" class="comment-reply-title">',
        'title_reply_after'  => '</h2>',
        'label_submit'=>'Have Your Say',
    ) );

    however, if I were you I would look into creating a child theme before you made any changes to your existing theme. It’s very easy and will save you a ton of headache in the future! (especially if your theme is updated)

    Thank you. Is there a reason entering the code I did above does not work when I enter it in functions.php? Trying to understand how it works for other changes in the future.

    For example, in the comment template form (displaying comments), WP currently has a title “One Comment”, “Two Comments”, etc… If I wanted to change that to say “One Response”, “Two Responses”, etc.., I found this info: https://developer.wordpress.org/themes/template-files-section/partial-and-miscellaneous-template-files/comments/

    It implies, I think, that the code I would use is something like:

    <h2 class="comments-title">
        <?php
            printf( _nx( 'One Response on "%2$s"', '%1$s Responses on "%2$s"', get_comments_number(), 'comments title', 'twentysixteen' ),
                number_format_i18n( get_comments_number() ), '<span>' . get_the_title() . '</span>' );
        ?>
    </h2>

    But entering that into functions.php does not seem to work. What doesn’t work about that?

    (By the way, I am using a child theme. Thanks for the tip.)

    Dion

    (@diondesigns)

    Is there a reason entering the code I did above does not work when I enter it in functions.php?

    Yes, there is a reason. Your code doesn’t belong in functions.php, it belongs in comments.php. 😉

    The functions.php file is for…functions. It is called much too early to directly output to the screen. I’ll bet if you instead edit the comments.php file of your child theme (and don’t create any PHP errors), the comments area will look the way you want.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Editing functions.php using wordpress codex. how to do the basics?’ is closed to new replies.