WordPress.org

Forums

[resolved] functions.php in child theme to twentytwelve causes blank page (14 posts)

  1. llizard
    Member
    Posted 2 years ago #

    I am working on a new wordpress site. I have been trying unsuccessfully to use functions.php in a twentytwelve child theme. If there is only <?php ?>, everything is fine. But the moment I add any coding at all, it causes my sister's wordpress site to show a blank page. The only fix is to go in via ftp and remove the functions.php file from my child theme folder.

    So far, this is all I have tried to add. But I would like to make other minor changes.

    <?php
    
    function favicon_link() {
    echo '<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">'."\n". '<link rel="icon" href="/favicon.ico" type="image/x-icon">';
    }
    add_action('wp_head', 'blog_favicon');
    }
    
    ?>

    I have stared at various help sites, including the wp codex and this forum, about using functions.php for child themes. Unfortunately, the answers on those pages have not worked for me. Please note that I only know enough about php to get myself in trouble.

    I do not understand how to go about declaring a function conditionally as outlined for someone who understands coding better than I in
    http://codex.wordpress.org/Child_Themes#Using_functions.php

    I read the following in twentytwelve function.php:

    you can override certain functions (those wrapped in a function_exists() call) by defining them first in your child theme's functions.php file.

    But as far as I can see, there is no existing function for a favicon link in the twentytwelve functions.php file that would be conflicting. I'm also unclear on how to either make the function conditional or how to define them.

    Thank you for any help you can offer.

    E Morris

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    You have syntax errors in your PHP. Try:

    <?php
    
    function favicon_link() {
    echo '<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">'."\n". '<link rel="icon" href="/favicon.ico" type="image/x-icon">';
    }
    add_action('wp_head', 'blog_favicon');
  3. llizard
    Member
    Posted 2 years ago #

    Augh! That was all? Who would have known that an extra closing curly bracket would cause the page to go blank?

    Thank you, Esmi.

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    When working on a site, it's worth keeping your eye on your site's error logs as the messages it contains can help you to pinpoint these kinds of issues. Your hosts should be able to help you in accessing your site's error logs.

  5. alchymyth
    Forum Moderator
    Posted 2 years ago #

    possibly enable DEBUG to get some error messages or warnings instead of a white page:

    http://codex.wordpress.org/Debugging_in_WordPress

  6. llizard
    Member
    Posted 2 years ago #

    Good ideas to check the error logs or enable DEBUG (I'll just have to remember to disable it once the site is live). Thank you.

    As for the recent fix to functions.php, alas, the shortcut icon is not actually appearing in the coding of the header. Is there something I'm missing? (I got that example of coding from the codex.)

  7. esmi
    Forum Moderator
    Posted 2 years ago #

    You can't use relative links in WordPress. They produce unpredictable results. Where do you intend to place this favicon file on the domain?

  8. llizard
    Member
    Posted 2 years ago #

    But the coding should appear when viewing the source code, shouldn't it?

    The favicon is already in the main file of the site. WordPress is in its own folder. Do I have to use the full link or do I really have to put the favicon into the wordpress folder too?

  9. esmi
    Forum Moderator
    Posted 2 years ago #

    the coding should appear when viewing the source code, shouldn't it?

    Yes. Can we see the site?

    And I'd suggest at least putting favicon into the wordpress folder. Ideally, I'd use the current theme's folder.

  10. alchymyth
    Forum Moderator
    Posted 2 years ago #

    is not actually appearing in the coding of the header

    the add_action is referring to a 'blog_favicon' function name, while the function is called 'favicon_link' ...
    also, make sure that the link points to the image; possibly by using http://codex.wordpress.org/Function_Reference/site_url (untested)

    try for example:

    function blog_favicon_link() {
    echo '<link rel="shortcut icon" href="' . site_url() . '/favicon.ico" type="image/x-icon">'."\n". '<link rel="icon" href="' . site_url() . '/favicon.ico" type="image/x-icon">';
    }
    add_action('wp_head', 'blog_favicon_link');

    (I got that example of coding from the codex.)

    can you post the link to it? so someone can check and edit the Codex chapter if it is incorrect.

  11. llizard
    Member
    Posted 2 years ago #

    Here it is:

    http://codex.wordpress.org/Child_Themes

    function favicon_link() {
        echo '<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />' . "\n";
    }
    add_action( 'wp_head', 'favicon_link' );

    It doesn't make sense that this won't work even if wordpress is in its own folder. Please note that this coding for the favicon is working on the rest of the site.

  12. llizard
    Member
    Posted 2 years ago #

    Thank you both for your replies.

    Esmi, I'm not authorized to show the URL to the site at this point. sorry. (It's not my site; it's my sister's.) I'll try putting the icon into the theme folder but it still doesn't make sense to me that that is necessary.

    I am connection problems today - hoping maybe this is part of the problem

  13. esmi
    Forum Moderator
    Posted 2 years ago #

    If it was me, I'd be placing the favicon file in the theme's folder and then using:

    function favicon_link() {
        echo '<link rel="shortcut icon" type="image/x-icon" href="<?php echo get_stylesheet_directory_uri();?>/favicon.ico" />';
    }
    add_action( 'wp_head', 'favicon_link' );
  14. llizard
    Member
    Posted 2 years ago #

    Thank you, both.

    I used Alcymyth's href="' . site_url() . '/favicon.ico" and put the favicons into the theme folder. Finally, the coding is appearing in the header area.

Topic Closed

This topic has been closed to new replies.

About this Topic