Skip to:
Content
Pages
Categories
Search
Top
Bottom

If statement for users logged in


  • project_subdomain
    Participant

    @project_subdomain

    Hi,
    is there anyone who can help me to get this part

    <div class="new-reply-link">
    
    	<a href="<?php bbp_topic_permalink(); ?>#new-post
    "class="reply-link-text">Reply</a> 
    </div></br>
    
    <ul id="bbp-topic-<?php bbp_topic_id(); ?>-lead" class="bbp-lead-topic">
    
    	<li class="bbp-header">
    
    		<div class="bbp-topic-author"><?php  _e( 'Author',  'bbpress' ); ?>
    </div>
    
    <!-- .bbp-topic-author -->
    

    into an if-statement for logged in users?

    I suppose that
    <?php if ( bbp_is_user_logged_in() ) { ... } ?>
    does not work that simple due to the additional php within, right?
    (no success so far..)

Viewing 2 replies - 1 through 2 (of 2 total)

  • Sam Rohn
    Participant

    @sam-rohn

    try the wp “is_user_logged_in” function

    https://codex.wordpress.org/Function_Reference/is_user_logged_in

    <?php
    if ( is_user_logged_in() ) {
    	echo 'Welcome, registered user!';
    } else {
    	echo 'Welcome, visitor!';
    }
    ?>

    or

    <?php if ( is_user_logged_in() ) { ?>
    <p>Welcome logged in user<p>
    <?php endif; ?>

    sam


    project_subdomain
    Participant

    @project_subdomain

    thanks, sam. tried several codes, nothing worked unfortunately (blank page):(

    add_action( 'loop_start', 'divs_only_when_logged_in' );
    
    function divs_only_when_logged_in() {
    
    <?php if ( is_user_logged_in() ) {?>
     
        <div class="new-reply-link">
    
    	<a href="<?php bbp_topic_permalink(); ?>#new-post
    "class="reply-link-text">Reply</a> 
        </div></br>
    
    <ul id="bbp-topic-<?php bbp_topic_id(); ?>-lead" class="bbp-lead-topic">
    
    	<li class="bbp-header">
    
    		<div class="bbp-topic-author"><?php  _e( 'Author',  'bbpress' ); ?>
    </div>
    
    <?php endif; ?>
    }  
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar