ThemeShaper Forums » Thematic

[closed]

Adding code to header.php

(12 posts)
  • Started 3 years ago by aberrant
  • Latest reply from helgatheviking
  • This topic is not resolved

Tags:

  1. aberrant
    Member

    Hello,

    I am trying to fix an issue with a jquery slider I have installed on my site and was told to place this code into the header.php file.

    <?php $browser = $_SERVER['HTTP_USER_AGENT'] . "\n\n";
    	$search = strpos( $browser, 'Win64' );
    	if ( $search != false && $search != 0 && $search != '' ) {
    		// This is for IE9 64-bit.
    		echo '<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8"/>';
    	} else {
    		// And this is for IE9 32-bit.
    		echo '<meta http-equiv="X-UA-Compatible" content="IE=8"/>';
    } ?>

    However, I do not know exactly where to put it. It says to place the code in the head tags, but after placing right before the first </head> tag, I experienced a database error on my site.

    Any help is greatly appreciated.

    Posted 3 years ago #
  2. you don't add stuff to header.php when you are child-theming w/ thematic

    wrap it all up in a function in your functions.php and add it to the wp_head hook

    function add_browser_test(){
    $browser = $_SERVER['HTTP_USER_AGENT'] . "\n\n";
    	$search = strpos( $browser, 'Win64' );
    	if ( $search != false && $search != 0 && $search != '' ) {
    		// This is for IE9 64-bit.
    		echo '<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8"/>';
    	} else {
    		// And this is for IE9 32-bit.
    		echo '<meta http-equiv="X-UA-Compatible" content="IE=8"/>';
    }
    }
    add_action('wp_head','add_browser_test');

    totally untested, ymmv

    Posted 3 years ago #
  3. aberrant
    Member

    Hi heigatheviking,

    Thanks so much for your help. So I would just copy and paste this function code into my functions.php file (make a copy and place it in my child theme folder) and that's it? Or do I have to add something somewhere else as well? I don't know what you mean by "add it to the wp_head hook". There is no wp_head hook in the functions.php file...

    Sorry I'm still a noob with PHP stuff!

    Thanks again for your help!

    Cheers,

    -A

    Posted 3 years ago #
  4. sowingseeds
    Member

    In your child theme's functions.php enter the code as given by helgatheviking (removing what you had added to the header.php).

    The wp_head hook is being called in the last line of code. It is not in thematic - but part of wordpress. As said the code is untested.

    Which slider are you using? Maybe if the code does not work as is that there is another way of making it work in wp.

    Posted 3 years ago #
  5. aberrant
    Member

    Hi sowingseeds,

    Hmmm, when I copy the functions.php file to my child theme folder, my site goes blank. Do I make a completely new functions.php file with only the code above in it? Would I leave the other fuctions.php file in the thematic folder?

    I'm using Easing Slider: http://www.easingslider.matthewruddy.com/

    I'm trying to resolve an issue in IE9 where the slider will only work after a refresh of the page. This code was actually on the premium slider version page (http://www.premiumslider.matthewruddy.com/) but I'm assuming it will work on this version just the same since it is only a browser hack of sorts.

    -A

    Posted 3 years ago #
  6. sowingseeds
    Member

    OK... first the code is untested, in terms of doing what you want, but it will not break your theme. If your site has gone blank I presume you cannot access the dashboard?

    You will need to download the childtheme functions.php and edit and then upload again.

    Sorry if I am asking the basics, but
    1) you have a child theme you activated... assuming yes. You do not change any thematic files only the ones in your child theme.
    2) There you have a style.css and a functions.php
    3)Enter the code on a new line after what is probably the last current line there
    // define('THEMATIC_COMPATIBLE_FEEDLINKS', true);
    So... function add_browser_test(){
    through to
    add_action('wp_head','add_browser_test');

    That code will not break your theme - make sure you have the code as is above.

    If however you can access your dashboard and the site is blank then there is a conflict elsewhere.

    Posted 3 years ago #
  7. aberrant
    Member

    Sowingseeds,

    Yes, the site went blank after copying the functions.php file to my child theme directory, but I deleted it and everything is back to normal. I'm curious as to why the site went blank after just copying this file to my child theme directory...any ideas?

    I have a bunch more code after // define('THEMATIC_COMPATIBLE_FEEDLINKS', true); in the functions.php file that is within the thematic directory.

    Thanks for the help.

    -A

    Posted 3 years ago #
  8. sowingseeds
    Member

    Did you add it at the end - after the ?>
    It needs to be placed before the final closing ?>.

    Posted 3 years ago #
  9. aberrant
    Member

    Even without adding this code, if I have a copy (exact copy from the thematic directory) of the functions.php file in my child theme directory, my site goes down. Not sure why it's doing this...

    Posted 3 years ago #
  10. you get white screens of death usually when you have an error in the code somewhere. parse errors (missing } , ; ) type characters).

    if ( isset($_GET['debug']) && $_GET['debug'] == 'debug')
      define('WP_DEBUG', true);

    add that to your wp_config.php file (in the wp root directory)

    then visit your site at

    yoursite.com?debug=debug

    will show you error messages that live sites often suppress, but that are helpful for figuring out where the error comes from.

    i did just test this locally, by pasting it into a theme i'm working on and it didn't break. so i am guessing it isn't the above code.

    Posted 3 years ago #
  11. evis
    Member

    I'm having problems with compability using the Thematic and Photo Lover themes. I'm not trying to add the add_browser_test to my functions.php but it doesn't help.

    I changed the code to add a third argument '1' to place the code first in the <head> tag, as I know this has helped before, but this doesn't place the code first after the <head> tag, only a bit higher up than it did without the argument...

    I really need to fix this in my project. Is there no plans to fix this in the themes? Or could you assist in how I can add the code where I want it?

    Posted 3 years ago #
  12. no idea what the photo lovers theme is and why thematic should be compatible. but if you look at header.php you will see

    // Creating the head profile
        thematic_head_profile();

    then if you look in library/extensions/header-extensions.php you'll see that function defined as:

    // Creates the HEAD Profile
    function thematic_head_profile() {
        $content = '<head profile="http://gmpg.org/xfn/11">' . "\n";
        echo apply_filters('thematic_head_profile', $content);
    } // end thematic_head_profile

    so boom, we've found where the head tag opens AND there is a filter we can latch on to

    function filter_head($content){
       return $content . '<meta http-equiv="bacon"/>';
    }
    add_filter('thematic_head_profile','filter_head');

    should get my useless bacon tag just after the head tag opens

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.