Viewing 4 replies - 1 through 4 (of 4 total)
  • you are using buddypress ?

    For the template part of your theme for that specific page (see https://developer.wordpress.org/themes/basics/template-hierarchy/ for details on themes and how the theme templates work and their hierarchy) you could include some PHP/WP API code in that page template like so:

    if ( !is_user_logged_in() ) {
        echo 'Message to display';
    }

    See https://codex.wordpress.org/Function_Reference/is_user_logged_in for more information on the ‘is_user_logged_in()’ function.

    Thread Starter maritk

    (@maritk)

    No, I am not using Buddypress. I am using Woocommerce and Theme my login. Thank you very much bemdesign, I will checkout the articles you are suggesting.

    So if I understand this correctly, there is no simple code I can insert on the page itself to make this happen?

    Hi,

    bemdesign’s suggestion is a good one and is used in a template, which means ALL of pages will show the message.

    When you say:

    So if I understand this correctly, there is no simple code I can insert on the page itself to make this happen?

    First of all, no I dont think there is a pre-written code for this.

    Secondly, your question implies that you wouold like this in some, not all pages.

    In that case, and if you want something easy to add to some pages, you can quite easily create a shortcode in your functions.php file and then use that shortcode in any page you wish.

    bemdesign has already given you a code exampple, and if you google “making a shortcode in wordpress” I am sure you will get many how to’s, such as this:

    https://codex.wordpress.org/Function_Reference/add_shortcode#Examples

    The first example will suit you if you use bemdesign’s code in the plugin code and throw that into functions.php

    Eg:

    function footag_func( $atts ) {
    
    	if ( !is_user_logged_in() ) {
        return 'Message to display';
    }
    }
    
    add_shortcode( 'footag', 'footag_func' );

    Just change footag and footag_func to whatever you like…
    Hope this helps πŸ™‚

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add a message for non-logged in users’ is closed to new replies.