Modifying Comments Form

  • DaveH

    #4877

    I don’t know if I’m posting this in the right place but if not please move it to where it belongs this is the best I could find.

    I’m trying to install WP-Members to require logins to view certain pages and to leave comments. It works well with blocked pages and comments but I apparently need to edit the comments.php as follows:

    Quote:
    You can make an easy modification to the theme comments.php file at the end where it generates the comments form with comment_form() – replace the comment_form(); call with this:

    [php]comment_form( array( ‘must_log_in’ => ‘You must be logged in to post a comment.’ ) );[/php]

    Update the url accordingly…

    I have installed a child theme (thanks Prasanna) and inserted the php code (with modified urls) into the functions.php. This just placed the line of code at the top of every post/page and did nothing for the login form. I then added the <?php and ?> tags at the beginning and end of the script and all that did was totally blank out my site and the only way I could think of restoring it was to delete the functions.php file through cpanel.

    How should I go about adding this code to the child theme to achieve the results I’m looking for?

    Thanks in anticipation.

    Dave

    Anonymous

    #29614

    That code should go in comments.php, not in functions.php. If you add this to functions.php file, it ruins your site. You can write a custom function (which goes in functions.php) and apply filters to comment template.

    If you want only logged in users to comment on all of your posts, you can just select Users must be registered and logged in to comment in WordPress Settings –> Discussion –> Other comment settings. It allows only logged in users to post comments. Or you want this to member only posts?

    DaveH

    #29615

    Prasanna, Thanks for responding so quickly.

    I don’t want to use the WordPress default because it’s ugly, it doesn’t contain the fields that I wish to collect, it doesn’t provide for retrieval of forgotten passwords nor modification of user passwords by users and did I mention it was ugly.

    From what I understand of what you’re saying is that this code needs to go into the comments.phd file but that will be overwritten every time we have an update and the way to prevent that happening is to use a child theme but there’s not much point in that because I can’t put the the contents.php into the child theme.

    Have I got it right? Sounds like a rock and a hard place to me

    Admin

    Syahir Hakim

    #29616
    Quote:
    From what I understand of what you’re saying is that this code needs to go into the comments.phd file but that will be overwritten every time we have an update and the way to prevent that happening is to use a child theme but there’s not much point in that because I can’t put the the contents.php into the child theme.

    Using a child theme, you can place codes into the comments.php file without actually putting the codes into the comments.php file.

    DaveH

    #29617

    Syahir, sorry but I don’t fully understand what you mean. I’ve sort of got it but not fully. Are you saying that there’s a way of putting the code somewhere in the child theme that will then alter the code in the comments.php file without me actually having to go into the comments.php file? If that’s the case then I don’t know how to do it and I’d really appreciate some instruction.

    Admin

    Syahir Hakim

    #29618
    Quote:
    Are you saying that there’s a way of putting the code somewhere in the child theme that will then alter the code in the comments.php file without me actually having to go into the comments.php file?

    Yes. Try inserting this code into your child theme’s functions.php file:

    function graphene_custom_comment_form_args( $args ){

    $args['must_log_in'] = 'You must be <a href="http://somewhere.to/go">logged in</a> to post a comment.';

    return $args;
    }
    add_filter( 'graphene_comment_form_args', 'graphene_custom_comment_form_args' );

    DaveH

    #29620

    Syahir, thanks for the help but sorry it didn’t work. All that happened was that the code appeared at the top of the screen with “logged in” appearing as anchor text which, when clicked, turned the whole screen white – had to delete the functions.php file through cPanel in order to access the site.

    Any other suggestions?

    Admin

    Syahir Hakim

    #29621

    Sorry, there was syntax error in the code I posted earlier. I’ve corrected it, so try again now.

    DaveH

    #29622

    Tried it again with no change – you can see for yourself at http://www.thesafetybloke.com

    Anonymous

    #29623

    PHP basic, add opening and closing tags.

    <?php
    /*Above code */
    ?>
Viewing 10 posts - 1 through 10 (of 12 total)

You must be logged in to reply to this topic.

Do NOT follow this link or you will be banned from the site!