Edit Logout shortcode for members

Hello,

In my membership I want to add a LOGOUT button for members in the members area. Added the shortcode [ms-membership-logout], but it pulls in the member's name and this text - YOU ARE LOGGED IN AS see the picture attached.

I want to add only the logout button with this text and member name. How can hide the title and username in this?

Thanks

  • Rupok
    • Support Ninja

    Hi chris

    Hope you had a wonderful day.

    You can do it by creating a MU Plugin. For creating a mu plugin, create a folder named "mu-plugins" inside your "wp-content" folder. Then inside that "mu-plugins" folder, create a file with any name and with a .php extension. Now paste the code inside that file and save.

    <?php
    
    add_action( 'wp_footer', 'hide_title_custom' );
    function hide_title_custom() {
        ?>
        <script type="text/javascript">
          jQuery(document).ready(function() {
            jQuery(".ms-logout-form").contents().filter(function(){
    		    return (this.nodeType == 3);
    		}).remove();
          });
        </script>
        <?php
    }

    For getting more idea on mu plugins, you can go through this article: https://premium.wpmudev.org/manuals/wpmu-manual-2/using-mu-plugins/

    Please let us know if you have any confusion. We will be glad to help.

    Have a nice day. Cheers!

  • Kasia Swiderska
    • Support nomad

    Hello Chris,

    Could you try this code instead:

    function wpmudev_change_logout( $translated_text, $text, $domain ) {
    	switch ( $translated_text ) {
    		case 'You are logged in as %s.' :
    			$translated_text = __( '', 'membership2' );
    			break;
    	}
    	return $translated_text;
    }
    add_filter( 'gettext', 'wpmudev_change_logout', 20, 3 );

    I've tested this on my site and this one should leave only the "Logout" link.

    kind regards,
    Kasia

  • Kasia Swiderska
    • Support nomad

    Hello Chris,

    Could you try to add this code (only for testing) to the functions.php file in your theme (at the very bottom of the file)? With support access I'm not able to check how code looks in mu-plugins and I double checked this on my installation and to be sure that this code works.

    kind regards,
    Kasia

  • Nithin
    • Support Wizard

    Hey Chris,

    Hope you are doing good today. :slight_smile:

    Glad to know it worked, since it's working when added to functions.php, there might be some error in the way you have added the code in mu-plugins folder. You could either carry on with this code in functions.php or if you still want it to be implemented in a mu-plugins folder, could you please try adding this particular code in a separate php file in the /mu-plugins folder.

    <?php
    function wpmudev_change_logout( $translated_text, $text, $domain ) {
    	switch ( $translated_text ) {
    		case 'You are logged in as %s.' :
    			$translated_text = __( '', 'membership2' );
    			break;
    	}
    	return $translated_text;
    }
    add_filter( 'gettext', 'wpmudev_change_logout', 20, 3 );

    Please do note to remove the function from the functions.php before testing this.

    I hope this helps. Have a nice day. :slight_smile:

    Kind Regards,
    Nithin

  • Nithin
    • Support Wizard

    Hey Chirs,

    I added the above code to a new file and then uploaded to mu-plugins folder. The logout works till the previous code is in functions.php, once removed it isn't working.

    This sounds odd, could you please check and confirm whether the name of your folder is "mu-plugins" and it is situated inside /wp-content folder.

    If you still have issues, could you please send me your FTP credentials.

    You can send that privately through our contact form: https://premium.wpmudev.org/contact/

    Select "I have a different question" for your topic - this and the subject line ensure that it gets assigned to me.

    Send in:

    Subject: "Attn: Nithin Ramdas"
    -WordPress admin username
    -WordPress admin password
    -login url
    -FTP credentials (host/username/password)
    -link back to this thread for reference
    -any other relevant urls

    Kind Regards,
    Nithin

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.