Categories
How To Themes Web Development WordPress

How To Convert an XHTML Website Template into a WordPress Theme

Converting an XHTML or HTML template into a WordPress theme is still a common task for developers, though the process has evolved with WordPress updates. This guide will walk you through modern best practices for converting a static HTML template into a fully functioning WordPress theme, considering WordPress 6.x and beyond.

What You Need

  • An HTML (XHTML) web template
  • A WordPress installation
  • A text editor (e.g., Visual Studio Code or Sublime Text)
  • An FTP client (like FileZilla)

The process involves splitting your HTML file into modular PHP templates, enabling WordPress to dynamically pull content from the database. This guide will cover the key steps for building a functional theme from your HTML template.

Step 1: Setting Up Your Theme Files

1. Create a Theme Folder

First, navigate to the wp-content/themes/ directory of your WordPress installation. Create a new folder named after your theme, such as my-theme. Within this folder, you’ll need the following files to get started:

  • style.css
  • index.php
  • header.php
  • footer.php
  • functions.php

Each file serves a distinct purpose in WordPress’ theme hierarchy. The index.php file will control the layout for most pages, while header.php and footer.php manage the header and footer sections, respectively.

2. Add Basic Theme Information

In your style.css file, add the following commented code at the top to define your theme:

/*
Theme Name: My Custom Theme
Theme URI: http://example.com/my-theme
Author: Your Name
Description: A custom theme based on an HTML template.
Version: 1.0
*/

Step 2: Splitting the HTML File

To integrate your template into WordPress, split your HTML file into the appropriate PHP files:

1. Header File (header.php)

Open your HTML file and copy everything from the <!DOCTYPE> declaration down to the start of your main content area (usually marked by a <div> or <main> tag). Paste this into header.php. Be sure to include the WordPress hook <?php wp_head(); ?> just before the closing </head> tag. This hook is essential for loading necessary WordPress styles and scripts.

2. Footer File (footer.php)

Next, copy the footer section (from the closing </main> or </div> to the end of the HTML document) and paste it into footer.php. Don’t forget to add the <?php wp_footer(); ?> call before the closing </body> tag. This enables plugin functionality that may be critical to your site.

3. Main Content File (index.php)

The remaining part of your HTML file, containing the main content, goes into index.php. You’ll need to replace static content with dynamic WordPress code using The Loop.

Adding The WordPress Loop

The WordPress loop is what handles all of your websites content. Its main components are:

  • The Title
  • The Content

The Loop can actually do a lot of things, but to keep things simple, those are the primary three things you’ll usually need access to. First you will need to identify where your content starts/repeats (if it repeats). The easiest way to do this is to look for your content’s header and begin The Loop there.

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  <h2><?php the_title(); ?></h2>
  <div><?php the_content(); ?></div>
<?php endwhile; endif; ?>

The Loop will usually end immediately after your content unless you are displaying extra information below your entries. You will also need to identify where your content begins and ends.

The Loop Code

Beginning:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

End:

<?php endwhile; endif; ?>

Template Tags Within The Loop

The Title

<?php the_title(); ?>

The Permalink

<?php the_permalink() ?>

The Content

<?php the_content('<p>Read more</p>'); ?>

Step 4: Add Navigation Menus and Widgets

To make your theme more dynamic, you’ll want to add support for navigation menus and widgets:

1. Register Navigation Menu

In functions.php, add this code to enable WordPress menus:

function my_theme_setup() {
    register_nav_menus(array(
        'primary' => __('Primary Menu', 'my-theme'),
    ));
}
add_action('after_setup_theme', 'my_theme_setup');

Then, in header.php, replace your static HTML navigation with:

<?php wp_nav_menu(array('theme_location' => 'primary')); ?>

Step 5: Testing and Activating the Theme

Now all you have to do is upload your theme folder which should now consist of:

  • An index.php file with custom code
  • A CSS file with header information about the theme
  • An images folder with all of your images

If all goes accordingly you should have a functional WordPress theme that allows you to add new pages and posts as well as use most popular WordPress plugins.

It is important to note that you will not be able to add widgets to your sidebar and people will not be able to comment on posts. There may also be some other limitations due to the themes simplicity.

More Resources

52 replies on “How To Convert an XHTML Website Template into a WordPress Theme”

Looking to convert my own portfolio website into wordpress and so far this looks to be the best wordpress theme tutorial i’ve found. I’ll report back with my results.

hi
I have this site along with 56 other related to property, which i purchased from a guy.

I would like to convert these sites from PHP site into wordpress
how easy is it ??
some of the sites have thousands of pages (page for every town village and city in UK) and the guy wrote a script for these sites the changed the text content, im also worried that if i change these site i find that all the content is the same and the script he wrote was blackhat and having duplicate content on that many pages will kill the site completely.
can someone advise please how i can sort this

as dropped from number1 google to between page 5 and 7 but still between number 1-3 on bing and yahoo.

You could ultimately use this tutorial but it might be best to hire a developer if you wont to take advantage of custom post types, sidebar widgets and the new navigation admin. Every town could be its own “town” custom post type.

Otherwise you could follow the tutorial above and look up how to implement sidebars on another site. Form there you could easily add each town as a new page and work form there. Then you could take advantage of a plugin like WordPress SEO to manage duplicate content.

You deserve a Nobel price 🙂 Thank you for this, mayby you need to continue this tutorial and explain wordpress functions in “page, single, comments.php…”

We have been looking way to make WordPress visually resemble (and function) as IP.Board so this could prove useful to our 4 year old New York tourism site.

Will have to come back to this later on a LAN connection that is able to handle the YouTube videos since we are on the go.

Some people find the videos easier. It’s hard to explain when people don’t know the correct terminology. The point was to write a post with quick advice on creating basic WordPress themes. I think the videos were perfect compliments to the very basic content.

It’s soo easy going through the tutorial, and I like the video tutorial most. Love to learn everything about WordPress. Now I am getting crazy about WordPress. Before I came to know coding and all these stuffs in WordPress, I make my sites converted by http://www.wpconverter.com. And interestingly, they have converted my old site to a brand new wordpress site. Starting from that moment onwards, I start loving wordpress and having fun with it. Plz post more wordpress related tutorials!

Every town could be its own “town” custom post type.Otherwise you could follow the tutorial above and look up how to implement sidebars on another site. Form there you could easily add each town as a new page and work form there.

Great tutorial my friend. Thanks.

I would like to learn next level with a sidebar, comments …
could you please help me.

Thanks
Jiji

I am satisfied that you simply shared this useful and important information with webdesign. It’s really a cool and helpful piece of information. Please stay us informed just like this. Thank you for sharing.

[…] 39 For this regard you can take the help of an expert Web Designer and if you have some knowledge about this you can do yourself. But you need to be careful while performing this task. Hope the below mentioned link becomes helpful to you in this regard. How To Convert an XHTML Website Template into a WordPress Theme […]

Three things that may help.

I always name my stylesheet ‘style.css’ as I think WordPress looks for this.

Always place a forward slash ‘/’ after the ” section

Finally, Your style sheet will need a header to be recognised by WordPress. Place the follow at the very top of your main style sheet.

/*

Theme Name: The title of the theme.

Theme URI: the theme’s uri

Description: Describe the theme

Author: Your name

Version: 1.0

License:

License URI:

Tags: key-words, key-words, key-words, key-words, key-words,

*/

Your theme should now show up in your admin panel.

Hope this helps.

Leave a Reply

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