Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1224361

    sharp-image
    Participant

    Hi,

    Can you tell me how I must translate: “You must be logged in to post a comment.” in the post section from users?
    For example: https://forevermusic.nl/fm-final/versterker-line6-flextone-2-e-100/
    This textline is not located in the .mo file or in my functions.php in my child-theme.

    Thanks
    Bouke

    #1224841

    Rue Nel
    Moderator

    Hello There,

    Thanks for writing in! The said phrase is coming from the WordPress comment form defaults. You may override that by adding the following code in your child theme’s functions.php file

    /**
     * Modify the "must_log_in" string of the comment form.
     *
     * @see http://wordpress.stackexchange.com/a/170492/26350
     */
    add_filter( 'comment_form_defaults', function( $fields ) {
        $fields['must_log_in'] = sprintf( 
            __( '<p class="must-log-in">
                     You must <a href="%s">Register</a> or 
                     <a href="%s">Login</a> to post a comment.</p>' 
            ),
            wp_registration_url(),
            wp_login_url( apply_filters( 'the_permalink', get_permalink() ) )   
        );
        return $fields;
    });

    Please do not forget to translate and make sure that you have the correct format.

    Hope this helps.

    #1225076

    sharp-image
    Participant

    Thanks for your answer. I placed this code:

    add_filter( 'comment_form_defaults', 'wpsites_comment_form_defaults' );
        $fields['must_log_in'] = sprintf( 
            __( '<p class="must-log-in">
                     Wil je een reactie geven op deze vette post? <a href="%s">Registreer</a> je  
                     <a href="%s">Login</a> dan hier!</p>' 
            ),
            wp_registration_url(),
            wp_login_url( apply_filters( 'the_permalink', get_permalink() ) )   
        );
        return $fields

    ;

    in my functions.php in my child-theme but nothing happen yet. Any idea what goes wrong?
    When I add a extra class in: <p class=”must-log-in test”> is this class not visible in the editor from the browser…

    Thanks!

    #1225079

    Paul R
    Moderator

    Hi,

    There a syntax error in your code.

    Kindly change it with this.

    
    /**
     * Modify the "must_log_in" string of the comment form.
     *
     * @see http://wordpress.stackexchange.com/a/170492/26350
     */
    add_filter( 'comment_form_defaults', function( $fields ) {
        $fields['must_log_in'] = sprintf( 
            __( '<p class="must-log-in">
                     Wil je een reactie geven op deze vette post? <a href="%s">Registreer</a> je  
                     <a href="%s">Login</a> dan hier!</p>' 
            ),
            wp_registration_url(),
            wp_login_url( apply_filters( 'the_permalink', get_permalink() ) )   
        );
        return $fields;
    });

    Hope that helps.

    #1225088

    sharp-image
    Participant

    Thanks,

    Still getting 2 errors. see the printscreen for the details.

    #1225110

    Rue Nel
    Moderator

    Hello There,

    Please use this code instead:

    /**
     * Modify the "must_log_in" string of the comment form.
     *
     * @see http://wordpress.stackexchange.com/a/170492/26350
     */
    function modify_must_login( $fields ) {
        $fields['must_log_in'] = sprintf( 
            __( '<p class="must-log-in">
                     Wil je een reactie geven op deze vette post? <a href="%s">Registreer</a> je  
                     <a href="%s">Login</a> dan hier!</p>' 
            ),
            wp_registration_url(),
            wp_login_url( apply_filters( 'the_permalink', get_permalink() ) )   
        );
        return $fields;
    }
    add_filter( 'comment_form_defaults', 'modify_must_login' );

    Hope this helps.

    #1225117

    sharp-image
    Participant

    Thanks that fixed the error! Can i do the same for the comment-reply-login class with the Log in to Reply text?
    https://forevermusic.nl/fm-final/test-3-jaar-oud-pioneer-ddj-wego-3-zwart/

    Do you have a little example for this one?

    #1225131

    Rue Nel
    Moderator

    Hello There,

    To modify the login text in the comments section, please check out this link:
    https://developer.wordpress.org/reference/functions/get_post_reply_link/

    Hope this helps.

    #1225159

    sharp-image
    Participant

    Hi Rue,

    Thanks but I fix this with a none display in the css because this extra login comment doesn’t make sense in the posts.

    That makes this topic fixeds. Thanks and have nice day.

    #1225177

    Rue Nel
    Moderator

    Hello There,

    We are just glad that you have figured it out a way to correct the said issue.
    Thanks for letting us know!

    Best Regards.