Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Wordpress - php suggestion

quickquick Member

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?

Comments

  • NomadNomad Member

    Something like this?

  • Simply use is_user_logged_in() with if statement

  • quickquick Member

    @jetchirag said:
    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

  • quickquick Member
    edited March 2017

    @jetchirag said:
    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

  • K4Y5K4Y5 Member

    @quick said:

    @jetchirag said:
    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.

  • JustAMacUserJustAMacUser Member
    edited March 2017

    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.

    Thanked by 4raindog308 WSS K4Y5 quick
  • K4Y5K4Y5 Member

    @JustAMacUser said:
    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

Sign In or Register to comment.