1

I am creating a WordPress Framework and within it there is the standard functions.php file. I will create new themes based on the framework which will use the framework functions.php file but have theme specific css/js/functions that will be needed. This is not a child theme. Can I in the main functions.php file call say theme_function.php which will house the theme specific functions,enqueues and other include calls?

3
  • 1
    Sure. What is stopping you?
    – fuxia
    Commented May 4, 2016 at 20:29
  • I've just never seen it before, so thought maybe the alternative is to put all the theme specific functions at the end of the functions.php file. But that seems a little harder to maintain if you need to change the framework or the theme.
    – Naz
    Commented May 4, 2016 at 20:35
  • 2
    The normal way nowadays is writing OOP and using an autoloader. That would save you the hazzle with include statements.
    – fuxia
    Commented May 4, 2016 at 20:40

2 Answers 2

2

The functions.php is convention for a file that will be automatically loaded by WordPress.

From there it is a normal PHP mechanics. You can further include any other PHP files in it. In some themes it is the only thing that a "root" functions.php does.

0

You can include or require other php files in your functions.php file or you could consider using a plugin. Plugins will run on any theme, so if this isn't what you want, you could consider some code in your plugin to check if your theme is active or not, such as:

<?php
$theme = wp_get_theme(); // gets the current theme
if ('twentytwelve' == $theme->name || 'twentytwelve' == $theme->parent_theme) {
    // if you're here twenty twelve is the active theme or is
    // the current theme's parent theme
    // Run your theme specific code here which will be ignored for other themes
}

Note - Code taken/modified from: How to check if a theme is active?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.