I'm including a file by include_once:

include_once( trailingslashit( get_stylesheet_directory() ) . '/recaptchalib.php' );

However I get warning from theme check plugin:

INFO: The theme appears to use include or require. 
If these are being used to include separate sections of a template from independent files, 
then get_template_part() should be used instead. 

How can I include the above file using the get_template_part?


If you take a look at the Codex page for get_template_part(), you fill find the following usage:

Load a template part into a template (other than header, sidebar, footer). Makes it easy for a theme to reuse sections of code and an easy way for child themes to replace sections of their parent theme.

Includes the named template part for a theme or if a name is specified then a specialized part will be included. If the theme contains no {slug}.php file then no template will be included.

<?php get_template_part( $slug, $name ); ?>

(string) (required) The slug name for the generic template.
Default: None

(string) (optional) The name of the specialized template.
Default: None

That means you can use the following:

<?php get_template_part( 'recaptchalib' ); ?>

You can use this to include every file in your theme directory.


The template part works like this.
If you have file in main folder then you can do like this:


In this example the file name is recaptchalib.php.

and if you have file in any other directory then you should called it by

 get_template_part('templates/layouts', 'recaptchalib');

In this example file is in templates/layouts and file name is recaptchalib.php.

  • Changed your answer a bit to get it just right ;-) – Mike Madern Jul 5 '13 at 8:00

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