Reputation: 4984
I'm working on a Wordpress multi-site.
I'm using the same functions on each site and so I'm repeating the functions in the function.php on each site.
I have a templates folder in the themes folder at the same level as different themes/sites.
In each site I'm using require to get common structures that are used on all the site that are in the templates folder.
<?php require(locate_template('templates/the_element.php'));?>
Is it possible to do the same sort of thing but with a function.
Can I require a function and pass varaiables in
Upvotes: 2
Views: 49
Reputation: 2588
There are a few things you could do - have a parent theme that all the themes use and as such you can share various files (and as such functions) amongst all of them.
You could make you shared code a plugin that can be installed on all of the sites as needed. So long as they use a shared plugin directory.
Or you could just include a file (can be called anything) into each theme so long as they all have access to it. See https://codex.wordpress.org/Child_Themes for more on child themes.
You might need to use php global variables to pass data to the file http://php.net/manual/en/language.variables.scope.php if you are passing data from sites files etc...
Upvotes: 1