2

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

1
  • What kind of common functions? Commented Dec 8, 2015 at 5:58

1 Answer 1

1

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...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.