Splitting a WordPress Template into Parts - Tutorial 14

Now, when the theme works for us as it should and displays our first page, we need to divide the page code into sections, It will help us:

  1. better navigate the code;
  2. do not repeat some parts of the code, which will be repeated on all pages.

First, let's separate the header and footer from the main part., There are special functions in wordpress for this., with which we can spread the code.

What to do with the template:

  1. Create at the root of your theme 2 file with names header.php and footer.php;
  2. Highlight page code content from top to bottom, stop after tag <body>.
  3. All that you selected, cut and transfer to header.php file.
  4. In the index.php file, at the very top, insert the function on a separate line
    <?php get_header(); ?>, anywhere in your template where this function is inserted, the code from the header.php file will be inserted. If done right, then the template should have a normal look and the styles should be saved.
  5. Next, cut out part of the code from the index.php file, responsible for the bottom of the site (the part that is repeated on all pages of the site) and move it to the footer.php file. This is the code, starting with a comment <!– Copyright –> to the end of the document.
  6. After transferring the code from index.php to footer.php, you need to call the footer.php file from index.php, for this, at the end of the index.php code, insert the function
    <?php get_footer(); ?>. If everything was done right, then your site will be perfectly displayed and the bottom part will not disappear.

A split WordPress template

If you did everything according to the points and correctly, then your template code should match mine in the archive below.

zip wordpress theme archive

This lesson is over, stay tuned for new releases, further will be even more interesting.


Buy WordPress hosting
WordPress tutor
Online tutoring services. List of courses I teach
  • Basic web design course;
  • Site layout;
  • General course on CMS WordPress and continuation of the course on template development;
  • Website development in PHP.
Read more on the page WordPress tutor
*/

Nikolaenko Maxim

Director of web studies ProGrafika. I am developing, website design and promotion. Always glad to new blog readers and good clients.


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Templates for WordPress
The best hosting in Ukraine
Stable hosting for Drupal