I would like to re-use some PHP classes and functions that I have written to display tables.
Right now, I am using XYZ PHP Code to display tables on multiple pages. In each snippet, I am defining a table class and related functions. I believe it would be much cleaner if this table class was defined only once.
How do I do this properly?
I would like to re-use some PHP classes and functions that I have written to display tables.
Right now, I am using XYZ PHP Code to display tables on multiple pages. In each snippet, I am defining a table class and related functions. I believe it would be much cleaner if this table class was defined only once.
How do I do this properly?
You're looking for something similar to PHPs require or include function.
In WordPress we can use get_template_part( 'example-folder/template' );
to get template.php
from the example-folder
.
You should also look into the get_template_part function to see the capabilities. If you're wanting to include outside variables into these, you can use PHP globals.
functions.php
, and PHP includes? – Tom J Nowell ♦ Commented Aug 7, 2018 at 20:18