Notifications
Clear all

[Solved] Hide Pre Code for Guest

5 Posts
2 Users
1 Likes
1,701 Views
Posts: 68
Customer
Topic starter
(@tutrix)
Member
Joined: 4 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: 4171
 Tom
Admin
(@tomson)
Famed Member
Joined: 9 years ago

Hi @tutrix,

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

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

Member
Posts: 68
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: 9 years ago

Famed Member
Posts: 4171

@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: 68
Customer
Topic starter
(@tutrix)
Member
Joined: 4 years ago

Hi @Tom

thank you very much, that works perfectly 😀 

Share:
Scroll to top