Notifications
Clear all

[Solved] Hide Pre Code for Guest

5 Posts
2 Users
1 Reactions
2,049 Views
Posts: 74
Customer
Topic starter
(@tutrix)
Member
Joined: 5 years ago

Is there a way to hide pre code for guests

Example via CSS class ".logged-in"

Pre Code display:none; for Guest

but "display: none;" can be deactivated in the CSS by the guests

4 Replies
Posts: 4213
 Tom
Admin
(@tomson)
Famed Member
Joined: 10 years ago

Hi @tutrix,

As far as I see you've already solved this task. Haven't you?

2 Replies
Customer
(@tutrix)
Joined: 5 years ago

Member
Posts: 74
Posted by: @tomson

Haven't you?

Unfortunately no, this is with CSS display: none; realized
The code can be made visible via the Browser Inspector

 Tom
Admin
(@tomson)
Joined: 10 years ago

Famed Member
Posts: 4213

@tutrix,

Try this. Put it in your current active WordPress theme functions.php file:

add_filter('wpforo_content_after', 'wpforo_hide_pre_for_guests', 10);
function wpforo_hide_pre_for_guests( $content ){
if( WPF()->current_user_groupid === 4 ){
$content = preg_replace('|<pre[^><]*>.+?<\/pre>|ism', '<a href="#" rel="nofollow">[' . wpforo_phrase('Please login to see the script', false) . ']</a>', $content);
}
return $content;
}
Posts: 74
Customer
Topic starter
(@tutrix)
Member
Joined: 5 years ago

Hi @Tom

thank you very much, that works perfectly 😀 

Share:
Scroll to top