{"id":159181,"date":"2016-09-22T13:00:24","date_gmt":"2016-09-22T13:00:24","guid":{"rendered":"https:\/\/premium.wpmudev.org\/blog\/?p=159181"},"modified":"2022-03-10T23:59:24","modified_gmt":"2022-03-10T23:59:24","slug":"convert-html5-template-wordpress-theme","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/convert-html5-template-wordpress-theme\/","title":{"rendered":"How to Convert Any HTML5 Template Into an Awesome WordPress Theme"},"content":{"rendered":"<p>What do you do when you can&#8217;t find the perfect WordPress theme? In all likelihood, you probably turn to a theme framework. However, every once in a while, you probably have this thought flit across your mind: &#8220;I should just code an HTML5 template and convert it into a WordPress theme.&#8221;<\/p>\n<p>But that&#8217;s just a pipe dream right? Let&#8217;s be realistic.<\/p>\n<p>The truth is, as long as you have some basic WordPress programming skills, converting an HTML5 template into a WordPress theme <em>is<\/em> within reach \u2014 provided you&#8217;re willing to put in the effort. In this post, I&#8217;ll show you how.<\/p>\n<p>Continue reading, or jump ahead using these links:<\/p>\n<ul>\n<li><a href=\"#why-convert-html-template-into-wordpress-theme\">Why Convert an HTML Template Into a WordPress Theme?<\/a><\/li>\n<li><a href=\"#setting-up-development-environment\">Setting Up Your Development Environment<\/a>\n<ul>\n<li><a href=\"#find-build-template\">Step 1: Find a Template or Build Your Own<\/a><\/li>\n<li><a href=\"#turn-html5-template-to-wordpress-theme\">Step 2: Turn the HTML5 Template into a WordPress Theme<\/a><\/li>\n<li><a href=\"#enqueue-scripts-and-styles\">Step 3: Properly Enqueue Scripts and Styles<\/a><\/li>\n<li><a href=\"#create-template-partials\">Step 4: Create Template Partials<\/a><\/li>\n<li><a href=\"#add-the-loop\">Step 4: Add the Loop<\/a><\/li>\n<li><a href=\"#replace-template-file-content-with-wordpress-functions\">Step 5: Replace Template File Content with WordPress Functions<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#next-steps\">Next Steps<\/a><\/li>\n<\/ul>\n<h2 id=\"why-convert-html-template-into-wordpress-theme\">Why Convert an HTML Template Into a WordPress\u00a0Theme?<\/h2>\n<p>There are a few good reasons why you might want to take on this project.<\/p>\n<ul>\n<li>Using an HTML5 template means you have complete control over every minute detail of the appearance of your website. Don&#8217;t like some part of the template? Change it. It&#8217;s a lot easier to tweak a simple HTML template than a complex WordPress theme.<\/li>\n<li>Using an HTML5 template means you don&#8217;t end up loading up your site with a bunch of features you don&#8217;t plan to use.<\/li>\n<li>If you want a WordPress theme that isn&#8217;t being used by thousands of other sites, converting an HTML5 template is one way to end up with a completely custom WordPress\u00a0theme.<\/li>\n<li>If you&#8217;ve never built a WordPress\u00a0theme before, converting a template will really stretch your WordPress development muscles \u2014 in a very good way.<\/li>\n<\/ul>\n<p>In this article, I&#8217;ll start with a simple HTML5 template and turn it into a full-fledged WordPress theme. Follow along, and you&#8217;ll be able to do the same.<\/p>\n<h2 id=\"setting-up-development-environment\">Setting Up Your Development Environment<\/h2>\n<p>In order to convert an HTML5 template into a WordPress theme, the first thing you&#8217;ll need to do is get your development environment set up.<\/p>\n<p>Here are the tools you will need in place before you start work:<\/p>\n<ul>\n<li><strong>A local server to power WordPress:<\/strong> There are many options to consider. We&#8217;ve detailed how to use <a href=\"https:\/\/wpmudev.com\/blog\/setting-up-xampp\/\" target=\"_blank\">XAMPP<\/a>, <a href=\"https:\/\/wpmudev.com\/blog\/develop-wordpress-locally-mamp\/\" target=\"_blank\">MAMP<\/a>, <a href=\"https:\/\/wpmudev.com\/blog\/how-to-set-up-wordpress-locally-for-pcwindows-with-wamp\/\" target=\"_blank\">WAMP<\/a>, <a href=\"https:\/\/wpmudev.com\/blog\/vvv-wordpress-development\/\" target=\"_blank\">VVV<\/a>, and <a href=\"https:\/\/wpmudev.com\/blog\/vagrant-wordpress-test-environment\/\" target=\"_blank\">Vagrant<\/a>. Pick one and get it working.<\/li>\n<li><strong>A local WordPress installation:<\/strong> It&#8217;s best to build a WordPress\u00a0theme while you have as few plugins activated as possible, so either create a new installation or use an existing installation after deactivating as many plugins as possible.<\/li>\n<li><strong>A git repo to keep track of your changes:<\/strong> While this isn&#8217;t technically a requirement, it&#8217;s a good idea. I&#8217;ve used <a href=\"https:\/\/github.com\/jpen365\/simple-blog-theme\" rel=\"noopener\" target=\"_blank\">GitHub<\/a> to track my changes and host the finished product, and Sourcetree to serve an easy-to-use GUI for git.<\/li>\n<\/ul>\n<p>You&#8217;re also going to need to be familiar with how WordPress themes work and have basic PHP coding skills before diving headfirst into this project. If the terms &#8220;template hierarchy&#8221;, &#8220;codex&#8221;, and &#8220;the loop&#8221; are unfamiliar to you, then you need to do some homework before jumping into this tutorial. You can learn what you need to know by taking a course or two, or by reading through our <a href=\"https:\/\/wpmudev.com\/blog\/wordpress-development-beginners-getting-started\/\" target=\"_blank\">beginner<\/a> and <a href=\"https:\/\/wpmudev.com\/blog\/wordpress-development-intermediate-theme-development-in-detail\/\" target=\"_blank\">intermediate<\/a> WordPress development series.<\/p>\n<p>If you get stuck at any point along the way and want to compare the template files I used with the finished WordPress\u00a0theme, you can get a copy of <a href=\"https:\/\/startbootstrap.com\/template-overviews\/blog-post\/\" rel=\"noopener\" target=\"_blank\">the template files from Start Bootstrap<\/a> and <a href=\"https:\/\/github.com\/jpen365\/simple-blog-theme\" rel=\"noopener\" target=\"_blank\">see my WordPress\u00a0theme&#8217;s source code at GitHub<\/a>.<\/p>\n<h3 id=\"find-build-template\">Step 1: Find a Template or Build Your Own<\/h3>\n<p>You can convert any HTML template into a WordPress theme. However, your task will be much easier if you pick a template layout that sticks closely to the core functionality built into WordPress: posts, pages, a sidebar, a header, and a footer. When looking at templates \u2014 or coding your own \u2014 think about how the parts of the template will translate into a WordPress theme.<\/p>\n<p>That doesn&#8217;t mean that you can&#8217;t convert any template into a WordPress theme. You can. However, the more non-traditional the template you select, the more work it will take to convert it into a fully-functional WordPress theme.<\/p>\n<p>I&#8217;m a minimalist when it comes to web design and a proponent of &#8220;mobile-first&#8221; design. As a result, a basic blog template based on Bootstrap is exactly the sort of thing I&#8217;m looking for.<\/p>\n<p>For this tutorial, I&#8217;ve settled on the <a href=\"https:\/\/startbootstrap.com\/template-overviews\/blog-post\/\" rel=\"noopener\" target=\"_blank\">Blog Post<\/a> and <a href=\"https:\/\/startbootstrap.com\/template-overviews\/blog-home\/\" rel=\"noopener\" target=\"_blank\">Blog Home<\/a> templates from Start Bootstrap.<\/p>\n<div  class=\"wpdui-pic-large   \" ><img loading=\"lazy\" decoding=\"async\" class=\"attachment-1364x1364 size-1364x1364\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2016\/09\/startup-bootstrap-blog-post-template.png\" alt=\"screenshot of the blog home template by start bootstrap\" width=\"1364\" height=\"530\" \/><\/div>\n<p>These templates are free, minimalist, will translate easily to WordPress, and they&#8217;re built with Bootstrap. Perfect.<\/p>\n<p>Once you&#8217;ve settled on the perfect them, or coded your own, you&#8217;re ready to move on to the next step: turning the template into a WordPress theme.<\/p>\n<h3 id=\"turn-html5-template-to-wordpress-theme\">Step 2: Turn the HTML5 Template into a WordPress\u00a0Theme<\/h3>\n<p>At this point, you should have an HTML5 template in hand. It should be composed of a directory that includes an <em>index.html<\/em> file and subdirectories for CSS and JavaScript resources. Copy the entire theme directory into the <em>wp-content\/themes\/<\/em> directory of your WordPress development site.<\/p>\n<p>The WordPress\u00a0theme is now located where it needs to be for WordPress to find it. However, to activate the WordPress\u00a0theme on your development site you have to make two changes:<\/p>\n<ul>\n<li>Rename <em>index.html<\/em> as <em>index.php<\/em>.<\/li>\n<li>Add a <em>style.css<\/em> file with a properly formatted <a href=\"https:\/\/codex.wordpress.org\/File_Header#Theme_File_Header_Example\" rel=\"noopener\" target=\"_blank\">theme file header<\/a> to the theme directory.<\/li>\n<\/ul>\n<p>Alternatively, you could just move the template&#8217;s primary CSS file up one level \u2014 out of the <em>\/css<\/em> directory and into the WordPress theme root directory. The key is that there must be a <em>style.css<\/em> file in the theme root directory, and it must include a proper theme header.<\/p>\n<p>If you&#8217;d like to, this would also be the right time to add a <a href=\"https:\/\/codex.wordpress.org\/Theme_Development#Screenshot\" rel=\"noopener\" target=\"_blank\">theme screenshot<\/a> to your theme directory.<\/p>\n<p>Once you make those changes, your WordPress\u00a0theme will be available for activation when you go to <strong>Appearance &gt; Themes<\/strong> in the WordPress admin area. Go ahead and activate your WordPress\u00a0theme and view your site front end.<\/p>\n<p>At this point, your WordPress\u00a0theme won&#8217;t look pretty. Here&#8217;s how my site looked at this point:<\/p>\n<div  class=\"wpdui-pic-regular  \"><img loading=\"lazy\" decoding=\"async\" class=\"attachment-670x670 size-670x670\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2016\/09\/without-styles.png\" alt=\"how my site looked before enqueuing styles and scripts properly\" width=\"670\" height=\"288\" \/><\/div>\n<p>What&#8217;s happening is that all of your theme&#8217;s CSS and JavaScript resources are contained in your theme directory, but your HTML template is set up to find the files relative to your site domain. In other words, WordPress\u00a0theme resources are located in <em>http:\/\/yourdomain.com\/wp-content\/themes\/your-theme-directory\/<\/em>, but your site template is looking for those resources in <em>http:\/\/yourdomain.com<\/em>.<\/p>\n<p>Obviously, it&#8217;s not finding them. So, the next step is to add CSS and JavaScript resources to our WordPress\u00a0theme in such a way that WordPress will find them.<\/p>\n<h3 id=\"enqueue-scripts-and-styles\">Step 3: Properly Enqueue Scripts and Styles<\/h3>\n<p><a href=\"https:\/\/wpmudev.com\/blog\/adding-scripts-and-styles-wordpress-enqueueing\/\" target=\"_blank\">The proper way to add scripts and styles to a WordPress theme<\/a> is to enqueue them. In order to do that, you will need to create a <em>functions.php<\/em> file in your theme&#8217;s root directory.<\/p>\n<p>Now, take a look at the CSS and JavaScript resources linked to your HTML template. The CSS resources will be added in the template head and the scripts may be added in either the head or just before the closing body tag.<\/p>\n<p>Once you&#8217;ve located all of the CSS and JavaScript resources you need to add to your WordPress\u00a0theme, build a function that enqueues all of the scripts and resources \u2014 don&#8217;t forget to include your theme&#8217;s <em>style.css<\/em> \u2014 and then hook the function into your WordPress\u00a0theme with <a href=\"https:\/\/codex.wordpress.org\/Plugin_API\/Action_Reference\/wp_enqueue_scripts\" rel=\"noopener\" target=\"_blank\">the <code>wp_enqueue_scripts<\/code> hook<\/a>. You&#8217;ll want to add the function and the hook to your theme&#8217;s <em>functions.php<\/em> file.<\/p>\n<p>Your enqueuing function will look somewhat different. However, for reference, here is a look at the enqueuing function I built:<\/p>\n<div class=\"gist\" data-gist=\"716c5647b842201eab77c02494224c04\" data-gist-file=\"enqueue-theme-assets.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/716c5647b842201eab77c02494224c04.js?file=enqueue-theme-assets.php\">Loading gist 716c5647b842201eab77c02494224c04<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>With the CSS and JavaScript resources enqueued, WordPress will now <em>recognize<\/em> the resources your theme depends on. However, in order to actually insert them into your live site, you need to add two hooks to your WordPress theme&#8217;s <em>index.php<\/em> file:<\/p>\n<ul>\n<li><code>wp_head<\/code>: Must be added just before the closing <code>&lt;head&gt;<\/code> tag in <em>index.php<\/em>.<\/li>\n<li><code>wp_footer<\/code>: Must be added just before the closing <code>&lt;body&gt;<\/code> tag in <em>index.php<\/em>.<\/li>\n<\/ul>\n<p>Here&#8217;s an approximation of what your <em>index.php<\/em> file should look like with these tags added:<\/p>\n<div class=\"gist\" data-gist=\"9fa2edaf6d2d96fa0fe06183c9bb83d5\" data-gist-file=\"add-wp_head-and-wp_footer-to-index.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/9fa2edaf6d2d96fa0fe06183c9bb83d5.js?file=add-wp_head-and-wp_footer-to-index.php\">Loading gist 9fa2edaf6d2d96fa0fe06183c9bb83d5<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>With those hooks added, and scripts and styles properly enqueued, your WordPress\u00a0theme should now look just like the original HTML template.<\/p>\n<p>The next step is to we&#8217;ll break <em>index.php<\/em> into the multiple parts so that we can reuse the header, footer, and sidebar with posts, pages, archive pages, and more.<\/p>\n\n<h3 id=\"create-template-partials\">Step 4: Create Template Partials<\/h3>\n<p>A <a href=\"https:\/\/developer.wordpress.org\/themes\/basics\/template-files\/#template-partials\" rel=\"noopener\" target=\"_blank\">template partial<\/a> is part of a WordPress theme that is only used when it is referenced by one of your theme&#8217;s template files.<\/p>\n<p>Let&#8217;s look at an example, virtually all WordPress themes break the document head out into a <em>header.php<\/em> file. That way, the header can be reused with pages, posts, the home page, archive pages, and the 404 and search pages. However, <em>header.php<\/em> is never called directly. It is only used when it is called by a template file such as <em>index.php<\/em>.<\/p>\n<p>In most cases, you will want to create at least three template partials:<\/p>\n<ul>\n<li><em>header.php<\/em><\/li>\n<li><em>footer.php<\/em><\/li>\n<li><em>sidebar.php<\/em><\/li>\n<\/ul>\n<h4>Create <em>header.php<\/em><\/h4>\n<p>Create a new file in your WordPress\u00a0theme&#8217;s root directory and name it <em>header.php<\/em>. Your theme&#8217;s <em>header.php<\/em> file will include the document type declaration, the opening HTML tag, the entire head element, the opening body tag, and your site navigation \u2014 in short, everything you want to appear at the top of every page of your site.<\/p>\n<p>Before you copy over that code, you need to create a <a href=\"https:\/\/make.wordpress.org\/core\/handbook\/best-practices\/inline-documentation-standards\/php\/#6-file-headers\" rel=\"noopener\" target=\"_blank\">file header<\/a>. Every file in your WordPress\u00a0theme should include a file header which is simply a brief explanation of the purpose of the file. Take a look at a couple of file headers from themes available from the WordPress theme directory. You&#8217;ll see that they all look quite similar. Your file header for <em>header.php<\/em> should look something like this:<\/p>\n<div class=\"gist\" data-gist=\"38a4c15822b19650140f7011b8f0ccef\" data-gist-file=\"file-header.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/38a4c15822b19650140f7011b8f0ccef.js?file=file-header.php\">Loading gist 38a4c15822b19650140f7011b8f0ccef<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>Once you have a file header in place, go ahead and copy over all of the header code from <em>index.php<\/em> over into <em>header.php<\/em>. Next, delete all of the header code from <em>index.php<\/em> and replace it with the <code>get_header()<\/code> WordPress function like this:<\/p>\n<div class=\"gist\" data-gist=\"eac243adf722060fa717a1cc7108f15c\" data-gist-file=\"get_header-example.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/eac243adf722060fa717a1cc7108f15c.js?file=get_header-example.php\">Loading gist eac243adf722060fa717a1cc7108f15c<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<h4>Create <em>sidebar.php<\/em> and <em>footer.php<\/em><\/h4>\n<p>Repeat the same process by creating a separate file for all sidebar contents and an additional file for all footer contents. After copying the code from <em>index.php<\/em> to the relevant files and delete it out of <em>index.php<\/em>, use the <code>get_sidebar<\/code> and <code>get_footer<\/code> WordPress functions to tie all of the template files together.<\/p>\n<p>When you&#8217;re done, <em>index.php<\/em> should begin with a file header and <code>get_header<\/code>, and end with <code>get_sidebar<\/code> followed immediately by <code>get_footer<\/code>. In between those three functions should be the main contents of your page.<\/p>\n<p>Here&#8217;s a simplified look at what <em>index.php<\/em> should look like at this point:<\/p>\n<div class=\"gist\" data-gist=\"a6025ad894f0c60c2b5ec88d47d959a4\" data-gist-file=\"all-template-partials-tied-together.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/a6025ad894f0c60c2b5ec88d47d959a4.js?file=all-template-partials-tied-together.php\">Loading gist a6025ad894f0c60c2b5ec88d47d959a4<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<h3 id=\"add-the-loop\">Step 4: Add the Loop<\/h3>\n<p><a href=\"https:\/\/codex.wordpress.org\/The_Loop\" rel=\"noopener\" target=\"_blank\">The loop<\/a> is the function that queries the WordPress database and generates the content displayed on every page of your WordPress website. In general, you will want to have at least two different versions of the loop:<\/p>\n<ul>\n<li>One version of the loop for your blog page that displays post titles, meta data, the featured image, and a post excerpt.<\/li>\n<li>A second version for your pages and individual posts that displays the full content of the page or post.<\/li>\n<\/ul>\n<p>In addition, you may want to refine the loop even further by crafting variations for individual pages, individual posts, search results pages, and more.<\/p>\n<p>At its most basic, here&#8217;s what the WordPress loop looks like:<\/p>\n<div class=\"gist\" data-gist=\"8dc9bd6adfd69c65309e7f9f7e02d3b9\" data-gist-file=\"basic-loop.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/8dc9bd6adfd69c65309e7f9f7e02d3b9.js?file=basic-loop.php\">Loading gist 8dc9bd6adfd69c65309e7f9f7e02d3b9<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>Of course, the comment in that bit of code would have to be replaced with WordPress functions to generate content and HTML tags to render that content properly.<\/p>\n<p>The loop needs to take pages, individual posts, the blog page, the homepage, archive pages, and the 404 and search pages into account. As a result, getting it all done in a single file is a challenge. For this reason, most public themes break the loop out of <em>index.php<\/em> and put it into multiple separate files with titles like <em>content.php<\/em>, <em>content-single.php<\/em>, <em>content-page.php<\/em> and so forth.<\/p>\n<p>If you decide to put the loop into multiple files, use <a href=\"https:\/\/developer.wordpress.org\/themes\/basics\/conditional-tags\/\" rel=\"noopener\" target=\"_blank\">conditional tags<\/a> along with <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/get_template_part\/\" rel=\"noopener\" target=\"_blank\">the <code>get_template_part<\/code> function<\/a> to reference the version of the loop you wish to use.<\/p>\n<p>My recommendation is to start simple and slowly iterate your loop(s) until you&#8217;re happy with what shows up on your WordPress site. If all else fails, the following loop should work for virtually every WordPress website, although the result may not be as stunning as you&#8217;d like. However, it&#8217;s a good jumping-off point if the loop is brand new to you.<\/p>\n<div class=\"gist\" data-gist=\"d012fdf8cd3611687c97abbd21d3ba14\" data-gist-file=\"a-simpe-loop.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/d012fdf8cd3611687c97abbd21d3ba14.js?file=a-simpe-loop.php\">Loading gist d012fdf8cd3611687c97abbd21d3ba14<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>Covering the loop in-depth is beyond the scope of this tutorial. However, it&#8217;s a topic we&#8217;ve covered before and you can learn all about it by reading <a href=\"https:\/\/wpmudev.com\/blog\/wordpress-development-intermediate-users-queries-loops\/\" target=\"_blank\" rel=\"noopener\">WordPress Development For Intermediate Users: Queries and Loops<\/a>.<\/p>\n<h3 id=\"replace-template-file-content-with-wordpress-functions\">Step 5: Replace Template File Content with WordPress Functions<\/h3>\n<p>This next step may vary considerably from one HTML template to the next. What you want to do is work your way through each template file \u2014 header, index, content (if applicable), sidebar, and footer \u2014 replacing every piece of static content with an appropriate WordPress function.<\/p>\n<p>Start with <em>header.php<\/em>. Every time your run into a bit of content, replace it with a WordPress function. If you aren&#8217;t sure what function to use, there are two things you can do to find the correct function:<\/p>\n<ul>\n<li>Take a look at the template files of a well-coded WordPress\u00a0theme such as Twenty Sixteen and copy what they do. Twenty Sixteen is GPL, copying is fine \u2014 even encouraged!<\/li>\n<li>Use Google to locate the appropriate functions in the WordPress Codex by searching for terms like &#8220;WordPress charset function.&#8221;<\/li>\n<\/ul>\n<p>One step that can be particularly tricky is setting up the header menu. Let&#8217;s take a minute to look at that step in detail.<\/p>\n<h4>Setting Up the Header Menu<\/h4>\n<p>Adding a header menu is a two-step process:<\/p>\n<ul>\n<li>Add the header location to your WordPress theme by adding a function to <em>functions.php<\/em>.<\/li>\n<li>Insert the menu into <em>header.php<\/em> being careful to duplicate the classes and ids employed by the HTML template.<\/li>\n<\/ul>\n<p>You will need to use <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/register_nav_menu\/\" rel=\"noopener\" target=\"_blank\">the <code>register_nav_menus<\/code> function<\/a> to add a menu location to your WordPress\u00a0heme. In the case of the example WordPress\u00a0theme, I dropped the following function into <em>functions.php<\/em>:<\/p>\n<div class=\"gist\" data-gist=\"fb1426f7fa610cb98bda818ffa1c4866\" data-gist-file=\"add-menu-area-to-functions.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/fb1426f7fa610cb98bda818ffa1c4866.js?file=add-menu-area-to-functions.php\">Loading gist fb1426f7fa610cb98bda818ffa1c4866<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>Next, you need to use <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/wp_nav_menu\/\" rel=\"noopener\" target=\"_blank\">the <code>wp_nav_menu<\/code> function<\/a> in <em>header.php<\/em> to generate your menu. Pay special attention to the classes and ids applied to the menu in your HTML template. You will need to duplicate these selectors so that the template&#8217;s CSS will be applied to your new menu. Thankfully, the WordPress function makes that pretty easy. Here&#8217;s how the code that adds the menu to my WordPress\u00a0theme&#8217;s <em>header.php<\/em> looks:<\/p>\n<div class=\"gist\" data-gist=\"760c27c03988773292a3110a44183734\" data-gist-file=\"add-nav-menu-to-header.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/760c27c03988773292a3110a44183734.js?file=add-nav-menu-to-header.php\">Loading gist 760c27c03988773292a3110a44183734<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>Note that I added two classes to the menu itself, <code>nav<\/code> and <code>navbar-nav<\/code>, as well as an ID and two classes to the menu container. I just copied these selectors from the HTML template. This ensures that the menu will pick up the template styles.<\/p>\n<h4>Setting Up Widget Areas<\/h4>\n<p>You will also need to set up sidebar, header, and footer widget areas as applicable based on the template you&#8217;re using. Adding widget areas is a two-step process:<\/p>\n<ul>\n<li>Use <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/register_sidebar\/\" rel=\"noopener\" target=\"_blank\">the <code>register_sidebar<\/code> function<\/a> to register the widget area in <em>functions.php<\/em>.<\/li>\n<li>Use <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/dynamic_sidebar\/\" rel=\"noopener\" target=\"_blank\">the <code>dynamic_sidebar<\/code> function<\/a> to add the widget area to the part of your theme where you want it to appear.<\/li>\n<\/ul>\n<p>The <code>register_sidebar<\/code> function accepts an array of values that includes the name of the widget area, the widget area ID, as well as the bits of HTML that should appear before after each widget and the widget title. The <code>register_sidebar<\/code> function is nested inside of a custom function, and that custom function is hooked into WordPress using <a href=\"https:\/\/developer.wordpress.org\/reference\/hooks\/widgets_init\/\" rel=\"noopener\" target=\"_blank\">the <code>widgets_init<\/code> hook<\/a>.<\/p>\n<p>Here&#8217;s how the function that registers the sidebar area for my WordPress\u00a0theme looks in my theme&#8217;s <em>functions.php<\/em>:<\/p>\n<div class=\"gist\" data-gist=\"9953227f9818b5f68a453c3940eccfb3\" data-gist-file=\"Register-sidebar.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/9953227f9818b5f68a453c3940eccfb3.js?file=Register-sidebar.php\">Loading gist 9953227f9818b5f68a453c3940eccfb3<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>With the widget area registered, we can add it to <em>sidebar.php<\/em> with <code>dynamic_sidebar<\/code>. The <code>dynamic_sidebar<\/code> function accepts the widget area ID that we registered with <code>register_sidebar<\/code> in <em>functions.php<\/em>.<\/p>\n<p>Here&#8217;s how the code adding the widget area to <em>sidebar.php<\/em> looks in my theme:<\/p>\n<div class=\"gist\" data-gist=\"bc447a4d189ba5e8c41bbc4bd75e0aa6\" data-gist-file=\"add-widget-area-to-sidebar.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/bc447a4d189ba5e8c41bbc4bd75e0aa6.js?file=add-widget-area-to-sidebar.php\">Loading gist bc447a4d189ba5e8c41bbc4bd75e0aa6<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>Those two functions work together to generate my theme&#8217;s sidebar widget area. The widget area will be contained in a div with a class of <code>col-md-4<\/code>. In addition, each widget will be contained in a div with a class of <code>well<\/code>, and each widget title will be nested inside of a fourth-level heading element.<\/p>\n<p>You can apply this process to add any number of widget areas to your WordPress\u00a0theme. All you have to do is:<\/p>\n<ol>\n<li>Create a different <code>register_sidebar<\/code> function with a unique ID for each widget area. You can stack all of your <code>register_sidebar<\/code> functions inside of a single custom function, and then initialize them all at once using the <code>widgets_init<\/code> hook.<\/li>\n<li>Use the <code>dynamic_sidebar<\/code> function and the unique widget area ID to load the widget area wherever you want it to appear: in the sidebar, header, or footer.<\/li>\n<\/ol>\n<h2 id=\"next-steps\">Next Steps<\/h2>\n<p>If you&#8217;ve followed along, step-by-step, at this point you have converted an HTML5 template into a functional WordPress theme. Congratulations!<\/p>\n<p>I followed this same process to create this WordPress\u00a0theme:<\/p>\n<div  class=\"wpdui-pic-large   \" ><img loading=\"lazy\" decoding=\"async\" class=\"attachment-1364x1364 size-1364x1364\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2016\/09\/completed-blog-post-theme.png\" alt=\"screenshot of completed simple blog theme\" width=\"1364\" height=\"529\" \/><\/div>\n<p>If you look back at the template at the top of this tutorial you&#8217;ll see that it&#8217;s pretty much a spot-on duplicate.<\/p>\n<p>While you&#8217;re undoubtedly pleased with what you&#8217;ve accomplished so far, there&#8217;s a good chance you aren&#8217;t completely satisfied with what you&#8217;ve created. The next steps you will probably want to take include:<\/p>\n<ul>\n<li>Creating custom templates and loops for individual posts, pages, search results, and a 404 page template.<\/li>\n<li>Adding a comments section to your individual posts and pages.<\/li>\n<li>Building custom widgets that match the styling of the widgets shown in your template.<\/li>\n<li>Internationalizing your WordPress\u00a0theme if you plan to make your theme publicly available.<\/li>\n<\/ul>\n<p>If you&#8217;ve made it this far, then you have the skills necessary to take on each of these additional tasks. However, walking you through the process is beyond the scope of this tutorial. If you need help taking on these tasks, take a look at the following resources that teach the concepts necessary to tackle these next steps:<\/p>\n<ul>\n<li><a href=\"https:\/\/wpmudev.com\/blog\/creating-custom-page-templates-in-wordpress\/\" target=\"_blank\">Creating Custom Page Templates in WordPress<\/a><\/li>\n<li><a href=\"https:\/\/wpmudev.com\/blog\/wordpress-development-beginners-widgets-menus\/\" target=\"_blank\">WordPress Development for Beginners: Widgets and Menus<\/a><\/li>\n<li><a href=\"https:\/\/wpmudev.com\/blog\/ultimate-guide-wordpress-localization\/\" target=\"_blank\">The Ultimate Guide to WordPress Translation and Localization<\/a><\/li>\n<\/ul>\n<h2>Wrapping up<\/h2>\n<p>Converting an HTML5 template into a WordPress theme can be a time-consuming, challenging endeavor. However, going through the process means you will end up with a genuinely unique WordPress theme, and if you&#8217;ve never converted a template into a theme before, you&#8217;re sure to learn a lot along the way as well.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What do you do when you can&#8217;t find the perfect WordPress theme? In all likelihood, you probably turn to a theme framework. However, every once in a while, you probably have this thought flit across your mind: &#8220;I should just code an HTML5 template and convert it into a WordPress theme.&#8221; But that&#8217;s just a [&hellip;]<\/p>\n","protected":false},"author":388460,"featured_media":159276,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[557],"tags":[9770,9912,4993],"tutorials_categories":[],"class_list":["post-159181","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development","tag-development-2","tag-html5","tag-templates"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/159181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/388460"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=159181"}],"version-history":[{"count":21,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/159181\/revisions"}],"predecessor-version":[{"id":206894,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/159181\/revisions\/206894"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/159276"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=159181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=159181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=159181"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=159181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}