functions.php in default theme - what is it? (8 posts)

  1. pcmt
    Posted 10 years ago #

    Pardon my ignorance. There's a file called functions.php in the default Kubrick theme for WP 2.0.1. The Codex says "Theme Functions — Themes can now include a functions.php file that will now be loaded like a plugin attached to the theme."

    What does that mean (roughly)?

  2. CalEvans
    Posted 10 years ago #


    Just what it says. It's a file that can contain PHP functions your theme needs to operate. It looks like it's just a way to separate them from the main theme files for convenience sake.

    I could be wrong...

    Cal Evans

  3. Kafkaesqui

    Posted 10 years ago #

    The main purpose of a theme's functions.php is that WordPress loads it (just after plugins), and makes the code in it globally available to more than just that theme's templates. It's this feature which allows the default theme to provide its "Header Image and Color" settings tab under Presentation in the WP admin.

  4. pcmt
    Posted 10 years ago #

    hmmm... I see what you mean about "Header Image and Color" for Kubrick. That's neat, I'd say.

    What if I make a new theme? (I'm basically asking if I can safely ignore this file when I make my own theme - the answer looks like "yes").

  5. Kafkaesqui

    Posted 10 years ago #

    "(...the answer looks like "yes")

    {Kaf nods affirmatively}

    The only theme template you can consider *necessary* is index.php. Everything else is optional (Ok, maybe not style.css. Really do need the template name and such, which is embedded in the stylesheet).

  6. TigerDE2
    Posted 10 years ago #

    In what order are the template files called when a functions.php file exists in the theme's folder? Is it called before all other files? :)

  7. maerk
    Posted 10 years ago #

    BTW, you can use functions.php to make your own template tags, I use it to insert the search form whereever I need it, or a not found message. It's brilliant.

    I also wrote a function to give you human times, like "2 hours ago" or "4 years ago".

    TigerDE2: I think so yes. At least, it's called before header.php. You might find you have a few problems with variables though, you need to declare them as global inside the function you want to use.

  8. TigerDE2
    Posted 10 years ago #

    Thanks, maerk.
    I just wanted to know because I want to i18n a (third-party) theme, and you've to "register" the gettext namespace before any gettexted strings...

Topic Closed

This topic has been closed to new replies.

About this Topic