Support » Fixing WordPress » Help with variables and session variables

  • Resolved SenseiAntonio


    Hello everyone,

    In my blog (, I have installed the AdSense Sharing Revenue and Earnings Plugins (

    In this plugin, I specify a php function in the Google Adsense code, so the Adsense client code changes with the adsense client code of each author, inserted previously in the administration panel.

    The first adsense advertisement includes this line of php code, in which, I presume, the variable is defined:

    <?php $id=$post->post_author; $google_id = kd_get_google_id($id); echo
    $google_id; ?>

    This outputs the adsense code of each author in his articles.

    The plugin creator said that in the next advertisements or Google Adsense blocks, and in the sidebar I have to put this php code:

    <?php echo $google_id; ?>

    The problem is that since the first advertisement is located in the single.php and the second in the sidebar.php, the variable google_id is not carried and it does not output anything in the sidebar.

    The author suggested to store the variable as a session variable. I presume that is for the variable to be carried along the blog in those pages.

    How do I define that variable as a session variable or similar, so the variable outputs the two times?

    Thank you very much in advance,

    Antonio Bustamante

Viewing 7 replies - 1 through 7 (of 7 total)
  • is the best resource for that type of coding, look at isset, and session varibles…

    The information there is not very clear to me. How can I do this in WordPress? Sorry, but I am not precisely a PHP expert 😉

    wordpress uses PHP, so you need to write the code that stores your neded information in a session varible , then the sidebar php code needs to refer to that session varble, its going to take some php know-how, and some trial and error on your part to make the modifications.

    sorry to say its not as easy as hey type

    blah=something, it does take some coding to get it done and I would suggest working with the plugin author if they will help you out at all.

    And is there a simpler way to do this? Such as, for example, defining the variable in the header, or something like that?

    I say this because I can handle some PHP things but not to the point where I define session variables. I somehow understand the concept but not how to apply it.

    Do you have any idea of a simpler way to do this?



    Sure you can define it inside header.php since that is called on every post, page etc. Then you can read the session varible in the sidebar and change the adsense id based on what is in the header.

    Problem is what happens if you have 2 or more authors and wordpress by default shows all posts regardless of who wrote it? Based on this that most recent author would be the one who’s adsense ID would be set in the session variable, so adsense credit wouldn’t be given to the other author.

    You would have to devise a way to only show posts by author X then adsense would display ads for author X only. Make sense?

    I use adsense myself, but the entire blog associate ID is for the site not multiple authors, that works perfect for my site, but trying to drive ads based on the author is going to put a bit of overhead on you programing in php and also determine the fairest way of showing ads based on author.

    I guess you could have each author have its own category and make the blog only show category X for author X, category Y for author Y and so on?

    Yes, you are right. I will try to figure out some solution to this. It doesnt sound so difficult, after all.

    Thank you very much, scifi, for your help 😉


Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Help with variables and session variables’ is closed to new replies.