I have some text blocks which are used various times.

I want to be able to add them as txt files to a folder in my theme, and then add one to specific posts and pages with either a shortcode or include.

I've found various plugins which don't work (deliver 'failed to open, no such file’) errors. And functions which can create shortcodes, but which can't handle multiple shortcodes in a single function.


Use get_template_part to insert regularly used files throughout your site. Example of use:

get_template_part( 'PATH/FILE_NAME' );

Where PATH is the location of the file you want to include, usually a folder within your theme/child-theme example(my-template-folder) NOTE! without leading slash. FILE_NAME is the name of your file, WITHOUT extension, example (my-regular-code.php becomes my-regular-code).

So the above would be get_template_part( 'my-template-folder/my-regular-code' ); and this would be placed within the main code of your page, where you want to display it.

As you point out you can also use SHORTCODES, there are plenty of code examples both here and google showing the correct way to make and insert

|improve this answer|||||
  • thanks. What I want to do though, is add such text blocks to the content of posts/pages rather than the templates. – gulliver Sep 10 '16 at 14:33
  • Ahh, right, if I'm understanding correctly, you want to add the text blocks directly within the content area of post type...then you will need a shortcode – Malisa Sep 10 '16 at 14:39

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.