New here? Register and read our Community Rules. Accounts are approved by hand.
Wordpress - php suggestion
Hello,
I am using wordpress with an adcode library bound in.
In my header.php I included this line:
<?php include('adcode.php'); ?>So what I would like to do is, to show these ads only to visitors. So logged in users (buddypress) should not get these .php file.
How would you do this?
0

Comments
Something like this?
Simply use is_user_logged_in() with if statement
so this could do the job?
if(!is_user_logged_in()){ <?php include('adcode.php'); ?> }Give it a try
Also remove php tags inside if statement
no chance, I see the code snippet in the header area
btw I am adding this code into the header.php of my theme. I think I should do it elsewhere
Theme functions file.
In the theme's
functions.php:add_action( 'wp_head', 'adcode' ); function adcode() { if ( ! is_user_logged_in() ) include( 'adcode.php' ); }As mentioned above, you really should put more logic-related stuff in the theme's functions.php file and leave the template files for just printing content to the screen, basic loops, etc.
Exactly!
I was just too lazy to type that up on a mobile at 5am :P