• I am trying to set the value of a php value depending on what browser is used. (Apologies if this is a very basic question, I am still learning… My site/theme is at https://www.vikingprincess.net)

    My code is basically…
    <?php include('browser_detection.php');?>
    <?php $user_browser = browser_detection('browser');?>
    <?php if ( $user_browser == 'msie' ) {$left_height=0; $right_height= 0;}?>
    <?php if ( $user_browser == 'gecko' ) {$left_height=658; $right_height=658;}?>

    …. then some code to adjust some heights.

    The problem is that I can’t get WP to pick up the php script. Where should I put it, and am I calling this script in the right way? Right now I’ve got the script in the themes/<themename> directory.

    Where can I read about the file hierarchy of WP / I got curious about folders like wp-includes etc.. ?

    Hope you can help!

    (I am am with a broken rib and won’t be doing anything this New Years Eve.. other than finish of my WP theme hopefully! Very exciting! ?? HAPPY NEW YEAR EVERYBODY, particularly the excellent and helpful moderators on this forum)

Viewing 5 replies - 1 through 5 (of 5 total)
  • Where can I read about the file hierarchy of WP / I got curious about folders like wp-includes etc.. ?
    Don’t touch anything in the so-called core files and directories (admin, includes).
    They are not for the user to mess around with!

    What you want (and need) is this:
    <?php include (TEMPLATEPATH . '/yourfilename.php'); ?>
    If the file is in your theme’s directory, it should work. Use it literally as it is, change ONLY the filename!

    Would like to do something similar, but not sure exactly how to do it. Would like to use two CSS stylesheets – one if user has IE, other for any other browser.

    Have found a php function that detects browser and have php if/else statement.
    https://techpatterns.com/downloads/scripts/browser_detection_php_if.txt

    These work fine with a simple “echo” statment, but not sure how to use these (possibly in the style.css file??) to dynamically switch css based on user’s browser.

    Luckily, my template is still in one piece (a miracle with the number of combinations I’ve tried!) but could really use some help with this one.

    gecko765, this is what’s in my header.php:

    <style type="text/css" media="screen">
    @import url( <?php bloginfo('stylesheet_url'); ?> );
    </style>
    <!--[if gte IE 7]>
    <style type="text/css" media="screen">
    @import url( <?php bloginfo('stylesheet_directory'); ?>/style-ie7.css );
    </style>
    <![endif]-->
    <!--[if IE 6]>
    <style type="text/css" media="screen">
    @import url( <?php bloginfo('stylesheet_directory'); ?>/style-ie6.css );
    </style>
    <![endif]-->
    <!--[if lt IE 6]>
    <style type="text/css" media="screen">
    @import url( <?php bloginfo('stylesheet_directory'); ?>/style-ie5.css );</style>
    <![endif]-->

    jabecker – This is it!! Thank you!!

    Sorry to take so long to get back, but “real world” kept me busy. This was exactly what I needed. Along the way, I also learned some important stuff about template tags. At first, I wasn’t too sure exactly how to use your information, but here is what I did, and – the important part – is that it worked!

    I needed one style sheet for IE and another for everyone else. IE seems to recognize the code, but the others do not (at least not as well).

    Answer: use default for everyone else and special one for IE.

    Created two css stylesheets and put both in the theme directory:
    default_stylesheet.css
    stylesheet_ie.css

    Modified my style.css (the one that names the theme to be used) so it uses the following to provide the default css:

    @import url (‘default_stylesheet.css’);

    In the Header.php:

    Removed original code: <link rel=“stylesheet” href=“<?php bloginfo(’stylesheet_url’); ?>” type=“text/css” media=“screen” />

    Put your code (see below) into header in its place. The first part calls the default_stylesheet.css (because it uses the ‘stylesheet_url’.) The second part provides the stylesheet to be used if the browser is IE (because it uses ‘stylesheet_directory’ and provides the name of the stylesheet to be used.)

    <!–Provides default stylesheet–>
    <style type=”text/css” media=”screen”>
    @import url( <?php bloginfo(‘stylesheet_url’); ?> );
    </style>

    <!–Provides stylesheet to be used if browser is IE–>
    <!–[if IE]>
    <style type=”text/css” media=”screen”>
    @import url( <?php bloginfo(‘stylesheet_directory’); ?>/stylesheet_ie.css );
    </style>
    <![endif]–>

    Been looking for this and was looking for conditional comments. Thanks for writing it so clearly ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Where to put browser-detect.php?’ is closed to new replies.