Support » Fixing WordPress » Favicon in child theme

  • I blame esmi for this 🙂
    I have created a child theme; just to change title colour.
    Having read http://codex.wordpress.org/Child_Themes
    I cannot get favicon to work; it totally changes my pages; I appreicate this is probably due to me creating a blank header.php with just the favicon code.
    For the time being, I have added the two favicon line to the twentyten theme header.php; I understand that this change can disappear in an upgrade.
    What is the minimum I can put in a header.php or functions.php in the child theme to make the favicon work?
    As I’m not hot with PHP, I assume I need more than just:

    <link rel="shortcut icon" href="http://www.windmillhillvillage.co.uk/images/favicon.ico" type="image/vnd.microsoft.icon" />
    <link rel="icon" href="http://www.windmillhillvillage.co.uk/images/favicon.ico" type="image/x-ico" />

    in a file to make it work.

    The above added to original theme works fine, what else do I need to type to add it to the child theme.
    Thanks
    John

Viewing 14 replies - 1 through 14 (of 14 total)
  • I would assume you would make a copy of twentytens header.php, the entire thing, and swap out/add your favicon

    or, something like:

    // add a favicon to your
    function blog_favicon() {
    	echo '<link rel="Shortcut Icon" type="image/x-icon" href="'.get_bloginfo('wpurl').'/favicon.ico" />';
    }
    add_action('wp_head', 'blog_favicon');

    in your child functions.php

    of course, this part get_bloginfo('wpurl').'/favicon.ico" should be modified to reflect where you put your favicon…. maybe changed to:

    get_bloginfo('stylesheet_directory').'/images/favicon.ico"
    if you keep the favicon in your child theme images directory

    Favicons sometimes just take time to update. You may have done everything you’re supposed to do, but they usually don’t switch over instantly.

    Thread Starter jasonbournecia

    (@jasonbournecia)

    Thanks Rev Voodoo, I copied the header.php to the child theme and just added the two lines to it.
    I was hoping it would go along the lines that BeardSquad mentioned.
    I just wondered what the minimum is you can put in a php file to make it work. I was hoping that my revised header.php just contained the two favicon lines; obviously not!

    well…for templates like that, the template replaces the original. So you have to include everything you need. Your child header.php is used instead of the parent header.php.

    for a functions.php you only need to include functions you wish to add or subtract from the parent. So the function I gave above for example, which would add your favicon, could be the entirety of your child functions.php file

    Thread Starter jasonbournecia

    (@jasonbournecia)

    Thanks Rev. Voodoo, appreciate you hanging in there.
    I tried that and messed up my site; changed back now.
    I possibly made an error with the apostrophes.
    Let’s say I had an images folder in the child theme, or I could leave an image either in root\images or twentyten theme\images, would you mind laying out that code above again. Thanks.
    I tried pasting in yours, then over pasting the bit linked to /images/favicon; I think I missed a bit possibly.
    Cheers
    John

    // add a favicon to your site
    function blog_favicon() {
    	echo '<link rel="Shortcut Icon" type="image/x-icon" href="'.get_bloginfo('stylesheet_directory').'/images/favicon.ico" />' . "\n";
    }
    add_action('wp_head', 'blog_favicon');

    should do it….this would look for the favicon in the images folder in your child theme parent theme/child theme/images/favicon.ico

    also, make sure the function is actually inside opening and closing php tags…. I’m not sure if you are using an already existent functions.php file in your child theme? If so, they should be there already….if not then:
    <?php
    goes before your code and:
    ?> goes after

    Thread Starter jasonbournecia

    (@jasonbournecia)

    Brilliant 🙂
    Thanks Rev. Voodoo, worked a treat.
    I now have an images folder, functions.php with just the favicon function and a style sheet in the child theme and all works great.
    It’s not until I try something, that I begin to see it. It’s the code, or more importantly, the apostophes etc that still stump me.
    Your help has been and will always be appreciated.
    John

    The only real way to learn that (barring school or study) is to just pick apart code

    That’s all I’ve done for the past few months to figure it out….. google stuff, download themes that do things I like, pick at the code, and then try to piece stuff together.

    With a little help from people on the forums, you start to get the hang of it

    Glad you got it working!!

    I am running a twenty-eleven child theme and I pasted the following code in my child themes function.php folder to display a favicon:

    // add a favicon to your site
    function blog_favicon() {
    	echo '<link rel="Shortcut Icon" type="image/x-icon" href="'.get_bloginfo('stylesheet_directory').'/images/favicon.ico" />' . "\n";
    }
    add_action('wp_head', 'blog_favicon');

    However, the favicon is not showing up. I assume I should have the favicon.ico stored in Twenty-eleven’s image folder (since my child theme is referencing it). Any ideas why this might not be working? The website is ohsaabasketball.com

    Thank you for any help!

    . I assume I should have the favicon.ico stored in Twenty-eleven’s image folder

    No – it should be in your child theme’s images folder.

    Thank you. All I have right now is a child theme and twenty eleven theme in my themes folder under wp-content. The child has two files, a style.css and functions.php. Do I need to create an images folder under my child too?

    Thank you!

    If you change the code to:

    // add a favicon to your site
    function blog_favicon() {
    	echo '<link rel="Shortcut Icon" type="image/x-icon" href="'.get_bloginfo('stylesheet_directory').'/favicon.ico" />' . "\n";
    }
    add_action('wp_head', 'blog_favicon');

    you can just add the .ico file to your child theme’s folder.

    Thank you very much! It worked!

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Favicon in child theme’ is closed to new replies.