Treehouse: Grow your CSS skills. Land your dream job.

WP: functions.php with includes inside not working…help!

  • # March 3, 2012 at 4:44 pm

    I’m building a theme with some custom post types.

    Normally all of these functions would just go in the functions.php file but I decided to make each post type function in a separate .php file.

    Basically in my functions.php file I have.

    < ?php include('filename.php'); ?>
    < ?php include('filename2.php'); ?>

    For some reason when there is two includes in the file neither work. But when there is only one inside the file it works. I tested both as just a single include and they both work fine. I’m lost…

    Anybody know what’s going on here?


    # March 3, 2012 at 5:39 pm

    so you are saying when you just include one of either of them it just works – when you include them both it doesn’t work?

    as a stickler I would say use include_once or require_once and not just include :)

    My other thought is how is the custom post type set up – have you copy and pasted one and kept the post registering name the same by accident?

    Oh and I would go into your WP_CONFIG file and turn on the debugging :D

    # March 3, 2012 at 6:18 pm

    Thanks for the reply!

    Yes with either one by itself… it works, when I have both at the same time it doesn’t work.

    I’ll double check the registering and try using include_once to see if that changes anything. I’ll also turn on the debugging, didn’t know about that one!

    Thanks again. I’ll reply back with an update if none of this works

    # March 3, 2012 at 6:33 pm

    Yea the debugging is awesome lol :D

    I don’t think include_once will fix it but it’s just a better way of doing it (it checks to see if it hasn’t already been included ya see)

    # March 3, 2012 at 6:39 pm

    So, I think I have found the problem by using the debugger.

    I’m getting : Fatal error: Cannot redeclare admin_init() (previously declared in /Users/davidschiffner/Sites/mamp/nvba/wp-content/themes/!NVBA-Theme/bio.php:40) in /Users/davidschiffner/Sites/mamp/nvba/wp-content/themes/!NVBA-Theme/event.php on line 42

    bio.php and event.php are my two files that I’m including in the functions.php

    I knew I did something wrong, I used admin_init in both files. Which screwed everything up.

    Thanks again for the help Rob

    # March 3, 2012 at 7:00 pm

    WP Debugger Wins again :D

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.