• Hello,

    I wish to slightly alter this line “You must be logged in to post a comment” that appears in the comment section for non-users/users not logged in.

    How can I do this? I can’t seem to find this line in my theme so I’m assuming it’s he WP core files. Any help I could receive would be appreciated!

Viewing 15 replies - 1 through 15 (of 15 total)
  • Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    One of two ways I can think of:

    1. Child theme
    2. Create simple plugin.

    The first method is simple in that you create a child theme and add just a few lines of code; downside being you will lose that alterations if you ever want to change themes.

    The second method will keep that message if you ever change themes.

    —-
    Method 1
    —-
    1. If you haven’t already create a child theme
    2. Create a functions file and add:

    add_filter( 'comment_form_default_fields', 'my_custom_phrase', 10 );
    function my_custom_phrase( $array ){
    	$array['must_log_in'] = "<p>Be sure to login prior to commenting.</p>";
    	return $array;
    }

    —-
    Method 2
    —-
    1. create a new folder in your plugins folder
    2. create blank php file and add:

    <?php
    /**
     * Plugin Name: Change message
     * Version: 0.1
     * Plugin URI:
     * Description: Change the 'you must log in' message
     * Author: jcastaneda
     * Author URI:
     */
    add_filter( 'comment_form_default_fields', 'my_custom_phrase', 20 );
    function my_custom_phrase( $array ){
    	$array['must_log_in'] = "<p>Be sure to log in first to comment.</p>";
    	return $array;
    }

    3. activate the plugin.

    Thread Starter Zainab R.

    (@crazy18gurl)

    Thank you for your response Jose!

    One quick question before I attempt this. The ‘logged in’ I would still keep as a link but how would I write the code so that after logging in the user is redirected to the last page. I know it’s along the lines of:

    ‘<a href=”http://siteurl.com/wp-login.php?redirect_to=…”&#8216;

    I just don’t know the string that would come in place at the end.

    Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    You can use something like:

    sprintf( '<a href="%s">Log in</a>', wp_login_url( get_permalink() ) );

    so in the $array it could be like:

    $array['must_log_in'] = '<p>' . sprintf( '<a href="%s">Log in</a> if you want to join the conversation.', wp_login_url( get_permalink() ) ) . '</p>';

    Thread Starter Zainab R.

    (@crazy18gurl)

    So I tried both methods, copied the codes exactly as you’ve given without making my changes yet and sadly neither worked. πŸ™

    Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    Does it work with any other theme?

    Hello Jose,
    I followed your Method 2 (from your post of 3 months ago) about modifying “You must be logged in to post a comment”.

    I installed and activated it as a Plugin in my WP-based page, but it makes no difference. Here is the page, in case it tells you some more info, http://rami.ybarniv.com/?page_id=667

    Can you suggest what can be the problem, please?

    Thanks MUCH for your help.
    Mike

    Hi,

    I think you could directly modify your “translation” (I don’t know the real term) file with extension “.po”, which (in your WP hosting server) should be inside the following directory /www/wp-content/languages/your translation file with extension “.po” (my is “it_IT.po”): I have done the same with my theme and it worked. At least you can try

    To modify the .po file (if your language is english, it should be “en_EN.po”: my language is italian and my file is “it_IT.po”) you should:

    1. download the free software “Poedit” here http://poedit.net/ and install it on your pc
    2. with some ftp client (or in some other way) you have to download your .po file in your pc and open it with Poedit
    3. find out wher the phrase “You must be logged in to post a comment” is, and change it directly
    4. save the file and upload it in the same directory from where you dowloaded it (in your WP hosting server)

    Good luck πŸ™‚ and regards
    Narad

    Ps I still don’t know if when you upgrade your theme this file will be overwritten… If I find out I’ll let you know. Anyway I’ll keep a backup copy on my pc

    Dear Narada,

    I thank you very much for your email reply to me.
    However, I couldn’t find a folder named “languages” under /www/wp-content/ so I can’t proceed.

    Can you give me an idea of where to find or get such a folder WITH whatever contents it has. Then, I’ll be able to modify it.

    Thanks again, Mike

    Hello Narada, it’s me again.

    I DID find the “languages” folder, Themes>twentyelever>languages which contains a file named, twentyeleven.pot.

    I followed your directions, downloaded it to my computer, installed Poedit-1.8-setup.exe, and opened the file with it.

    However, there is nothing in this .pot file which resembles the sentence I am trying to modify, which is: “You must be logged in to post a comment”.

    Please let me know in case you have other ideas about this issue.

    Thanks much, Mike

    Hi Mike, the extension of the file it’s not “.pot”, but “.po”. Please read carefully what follows

    if your language is english, you should:
    1. search inside your “root directory” in your hosting server (via ftp) for a file named “en_EN.po”.
    2. The output of the search probably gives you many such files. I don’t know in your WP installation, but in mine “the right” file is here: “www/wp-content/languages/” and is named “it_IT.po”, becouse my language is italian. Of course yours must be named “en_EN.po”.
    3. follow the instructions which I gave in my previous post from point 2 to 4

    2. with some ftp client (or in some other way) you have to download (copy) your .po file in your pc and open it with Poedit
    3. press ctrl+f to find out where the phrase “You must be logged in to post a comment” is, and change it directly
    4. save the file and upload it in the same directory from where you dowloaded it (in your WP hosting server)

    For me it has worked… but I have to translate from english to italian: I’m not shure if with Poedit it’s possible change the english phrases directly

    Regards
    Narada

    Hi Narada,

    I found out that the code for changing the TEXT of “must log in” is here, wp-includes/comment-template.php:2226

    I changed the string to “Please LOG IN to post a comment”:

    sprintf( __( 'Please <a href="%s">LOG IN</a> to post a comment.' ), wp_login_url(apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) )

    However, I still don’t know how to control the formatting (style) of that text. For example, I want to make it Bold and change the Font size. I guess controlling the formatting must be somewhere else. I wish to find out where that is?

    As to POEDIT, it doesn’t help me with formatting the “must log in” message. First, it ignores my edits (maybe I need to purchase the PRO version of the programs); second, it won’t accept HTML Tags (to control formatting).

    I enjoy “working” with you,

    Mike

    Thanks Mike, I’m glad to help people… and happy that you solved

    AS per my knowledge Poedit doesn’t allow to change formatting styles in .po files… I think it’s not possible, but I’m not shure. You could verify with a freelancer expert in this field: there are many web site where you can find one: www.odesk.com; www.freelancer.com/β€Ž; etc… and they are not so expansive

    Best regards
    Narada

    First, be aware that you’ve edited a core WordPress file (which is not recommended), and you’ll lose that change the next time WordPress is updated.

    Text formatting is controlled by your theme; Poedit is simply for translating strings. You can edit the formatting of that text with some custom CSS, and if you post a link to a page that shows the text, we can give more specific advice.

    Stephen, thank you for your help. My website is http://rami.ybarniv.com/?page_id=701

    I want to format this text: “Please LOG IN to post a comment.”

    I know that the way I already changed the original TEXT (but not its formatting) will disappear the next time WP updates, but I don’t know how to do it in a way which WILL last.

    I am fully aware, and already created a Child of the Twentyeleven Theme I am using, but I don’t know how to tell it to change, and/or to format that sentence.

    Additional info: I am using https://wordpress.org/plugins/comment-guestbook/ to create my Guestbook page. I believe that this Plugin simply refers to the original WP Guestbook.

    Thanks again for your help,

    Mike

    In your child theme’s stylesheet, use this code:

    .must-log-in { color: #ff00ff; }
    .must-log-in a { color: #ff00ff; }

    You might benefit from learning how to use a web inspecting tool like Firebug. Here’s a good beginner tutorial: http://www.themesandco.com/snippet/firebug-best-spent-6-minutes/

    Since you’ve already got a child theme, you can easily alter that text with a custom function in your functions.php:

    <?php
    
    add_filter( 'comment_form_defaults', 'my_custom_phrase' );
    function my_custom_phrase( $array ){
    	$array['must_log_in'] = sprintf( __( '<p class="must-log-in">Please <a href="%s">LOG IN</a> to post a comment.</p>' ), wp_login_url( get_permalink() ) );
    	return $array;
    }
Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Alter "You must be logged in to post a comment" line’ is closed to new replies.