The MU forums have moved to WordPress.org

How to insert code in all themes? (11 posts)

  1. badlagar
    Member
    Posted 17 years ago #

    I am searching for a hack to insert code in all sidebars of my site.

    Any one knows any metod without change theme by theme?

  2. stutley
    Member
    Posted 17 years ago #

    Widgets?

  3. badlagar
    Member
    Posted 17 years ago #

    Yes, but how can i put a widget in all blogs and the user dont know that the widget is put?

  4. drmike
    Member
    Posted 17 years ago #

    I don't even think there's any hooks within the sidebar that one could use. The only thing I can think of right off is putting the code into the meta function but you can get around that by not displaying the meta widget.

    Hmmm... It's too early for this. :)

    I can think of lots of ideas but they all mean going through the themes one by one.

    Does it have to be within the sidebar? What are you trying to add in anyway? I'm guessing Adsense or something simular.

  5. badlagar
    Member
    Posted 17 years ago #

    drmike, i want to add to the sidebar Adsense, but i have done a script to show it only if you come from Google (for not put adsense to the readers of the blog).

    Any idea for put this in all blogs?

  6. stutley
    Member
    Posted 17 years ago #

    I think drmike is right - there are no hooks that allow you to force a function or a piece of code in the sidebar. The only thing I can think of is to go through the themes each by each. Sorry :)

  7. badlagar
    Member
    Posted 17 years ago #

    Ok, thanks to all! :)

  8. drmike
    Member
    Posted 17 years ago #

    Actually yes. (edit: That's yes by the way to having an idea. I still not away of an idea for the sidebar)

    Take a look at the admin-bar plugin from over at wpmudev.org It adds in a bar along the top if your user is logged in. You could probably work something out of that. if not, put the code you're trying to add in into a txt file and send it to me as an attachment at theapparatus at gmail dot com and I can probably look at it this weekend.

    Hope this helps,
    -drmike

  9. badlagar
    Member
    Posted 17 years ago #

    I can put the code here, there is no problem ;)

    This is the code that i want to put in the sidebar:

    function vienedegoogle()
    {
    if(empty($_SERVER['HTTP_REFERER']))
    return false;

    $referer = urldecode($_SERVER['HTTP_REFERER']);

    if (preg_match('|^http://(www)?\.?google.*|i',$referer))
    {
    return true;
    }else{
    return false;
    }
    }

    if(vienedegoogle()){
    ---MY ADSENSE CODE HERE---
    }

  10. badlagar
    Member
    Posted 17 years ago #

    drmike any idea? :S

  11. dsader
    Member
    Posted 17 years ago #

    If widgets are coded into every sidebar, and who isn't doing that anyway, then put your adsense code into the widgets.php.

    about line 135
    function dynamic_sidebar($name = 1) {
    global $registered_sidebars, $registered_widgets;
    echo 'My Adsense Goes Here';

About this Topic