WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm creating a template, and one of the files is getting overloaded with pig-ugly mixed html and php.

At first I thought that maybe I should cut out chunks of the code, and call them using include().

Then I thought - maybe there is a wordpress way to do things. Perhaps I should abstract out my logic from the templates, by putting the custom loop in functions.php, and then calling it somehow from the template.

How do I do this?

share|improve this question
up vote 1 down vote accepted

This is personal preference and there are many ways it can be done. I like to keep my templates as clean as possible and use get_template_part() to include the various parts.

For parts of code that is used often I like to create functions and call the functions in the templates.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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