How to display different links for logged in and logged out users?

前端 未结 8 1033
天涯浪人
天涯浪人 2021-01-26 02:23

When a user is not logged in I am trying to show

Support || Log In

When they are logged out it should say

Support || Log Out 
<         


        
8条回答
  •  独厮守ぢ
    2021-01-26 02:44

    Another way to display content for users with a shortcode. Post this into functions.php

    // When member is logged in [memberin]
    
    add_shortcode( 'memberin', 'member_check_shortcode' ); 
    function member_check_shortcode( $atts, $content = null ) {
    function member_check_shortcode( $atts, $content = null ) {
      if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
    return $content;
    return '';
    }
    
    // When member is logged out [memberout]
    
    add_shortcode( 'memberout', 'member_check_shortcode_out' );
    function member_check_shortcode_out( $atts, $content = null ) {
      if (!is_user_logged_in() && !is_null( $content ) && !is_feed() )
    return $content;
    return '';
    }
    

提交回复
热议问题