0

I am using a Twitter Timeline PHP framework to display a list of tweets with favorite/retweet interactions. I have it all configured and working as a standalone solution currently and I am wondering what the best way to incorporate it into my custom Wordpress theme would be. Is it as simple as creating an inc folder, placing all the files in there and then adding <?php include_once('inc/twitter.php'); ?> into my template file where I want the tweets to display? Or is there a better practice?

2

It is that simple. Code away!

if it's in a plugin I do this:

$plugin_url = plugin_dir_url( __FILE__ );
include_once($plugin_url . 'inc/twitter.php');

if it's in a theme file

include_once(get_stylesheet_directory_uri().'inc/twitter.php');
5
  • Great, thank you very much for the explanation of both methods! – user13286 Feb 22 '18 at 17:17
  • FYI, using get_stylesheet_directory_uri() is incorrect because it will return the URL path to the file, not the path suitable for including the file. Also, it will return the path to the child theme if you have one, which you probably don't want happening either. Use get_template_directory() instead. – Otto Feb 22 '18 at 20:12
  • why on earth would you not want to use a child theme if you're custom coding? – rudtek Feb 22 '18 at 20:16
  • If you're, you know, developing a theme? Where do you think parent themes come from? – Jacob Peattie Feb 22 '18 at 23:57
  • Also, these days there's more useful functions: get_theme_file_path( 'inc/twitter.php' ) and get_parent_theme_file_path( 'inc/twitter.php' ). Because the path to the file is an argument you can have a parent theme fallback for non template files. – Jacob Peattie Feb 22 '18 at 23:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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