Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to hide from public

  • @streng

    Participant

    Hi,

    I try to acchieve to hide all content between code tags from public users. I want to show this content only for logged users. Any idea how to achieve this?

    The main reason why I want to do this is that, between code tags sometime contain content like quotation which can impact my SEOrank because isnt unique.

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • @robin-w

    Moderator

    Add this to your functions file

    add_filter( 'bbp_get_reply_content', 'rew_remove_code_tags', 10, 2 );
    
    function rew_remove_code_tags ($content, $reply_id) {
    	if (!is_user_logged_in()) {
    		$content = preg_replace("/<code>.+?<\/code>/i", "", $content);
    	}
    	
    return apply_filters( 'rew_remove_code_tags', $content, $reply_id );
    }

    @streng

    Participant

    Thanks, but it work only if text between code is on one row. If someune post log test separated by rows, then didnt work properly.
    Any idea how to fix ?

    @streng

    Participant

    Ok i find a solution i just change flag /i for flag /s

    $content = preg_replace("/<code>.+?<\/code>/S", "", $content);

    But i have a question it is correct solution? No performace issue ?

    @robin-w

    Moderator

    this does that

    add_filter( 'bbp_get_reply_content', 'rew_remove_code_tags', 10, 2 );
    
    function rew_remove_code_tags ($content, $reply_id) {
    	if (!is_user_logged_in()) {
    		$content = preg_replace('~<code(.*?)</code>~Usi', "", $content);
    	}
    	
    return apply_filters( 'rew_remove_code_tags', $content, $reply_id );
    }

    @robin-w

    Moderator

    But i have a question it is correct solution? No performace issue ?

    yes it has a performance issue, every line of code has a performance issue.

    No idea by what you mean ‘is it the correct solution’ This is a help service for bbpress not a free bespoke website service. I have already gone beyond the usual to help you.

    It is up to you to decide the balance of SEO against performance, not me.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar