{"id":6015,"date":"2019-11-05T12:34:17","date_gmt":"2019-11-05T12:34:17","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=6015"},"modified":"2026-03-10T10:07:13","modified_gmt":"2026-03-10T10:07:13","slug":"create-wordpress-theme-html5-css3","status":"publish","type":"post","link":"\/my\/tutorials\/create-wordpress-theme-html5","title":{"rendered":"How to Create a WordPress Theme: 6-Step Process with Code"},"content":{"rendered":"<p>While you can always install a pre-made WordPress theme, creating a custom one makes your website more unique.<\/p><p>With a custom theme written in popular coding languages like PHP, HTML, and CSS, you can also select specific features or elements based on your needs to improve site performance.<\/p><p>Fortunately, creating a WordPress theme from scratch is not always complicated. For instance, a simple theme with a single layout and static elements is easy since you only need two files.<\/p><p>In this tutorial, you will learn how to create a WordPress theme from scratch in six steps. We will also explain how to implement responsive design and other important concepts for customization.<\/p><p class=\"has-text-align-center\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/HTML-Cheatsheet.pdf\" target=\"_blank\" rel=\"noopener\">Download complete HTML cheat sheet<\/a><\/p><p>\n\n\n\n<div class=\"protip\">\n                    <h2 class=\"featured-snippet title\">How to Create a WordPress Theme<\/h2>\n                    <p>Step 1. Create and Store the Template Files<br>\nStep 2. Set Up the Initial CSS Stylesheet<br>\nStep 3. Make the WordPress Theme Functional<br>\nStep 4. Build a Layout for Your Custom Theme<br>\nStep 5. Improve Your Design on the CSS Stylesheet<\/p>\n                <\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-creating-a-wordpress-theme-development-area\">Creating a WordPress Theme Development Area<\/h2><p>When developing your own theme, avoid using it on the live site immediately since it might cause errors.<\/p><p>Instead, set up a WordPress staging area using the built-in tool that came with Hostinger&rsquo;s <a href=\"\/my\/wordpress-hosting\">Business WordPress hosting plan<\/a>. It is quicker than setting up a local environment since you don&rsquo;t need to install multiple tools.<\/p><p>To do so, navigate to <strong>hPanel<\/strong> &rarr; <strong>Websites <\/strong>&rarr; <strong>Dashboard<\/strong>. From the sidebar, click <strong>WordPress<\/strong> &rarr; <strong>Staging<\/strong>.<\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/03\/staging-tool-location-in-hpanel-website-management-page.png\"><img decoding=\"async\" width=\"476\" height=\"310\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/03\/staging-tool-location-in-hpanel-website-management-page.png\" alt=\"Staging tool location in hPanel's website management page\" class=\"wp-image-106345\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/staging-tool-location-in-hpanel-website-management-page.png 476w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/staging-tool-location-in-hpanel-website-management-page-300x195.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/staging-tool-location-in-hpanel-website-management-page-150x98.png 150w\" sizes=\"(max-width: 476px) 100vw, 476px\" \/><\/a><\/figure><\/div><p>Finally, <a href=\"\/my\/tutorials\/wordpress-staging-environment\">create the WordPress staging area<\/a> by switching to the<strong> Staging<\/strong> tab and clicking <strong>Create staging<\/strong>. Enter your preferred subdomain and click <strong>Create<\/strong>.<\/p><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-large\"><a href=\"\/my\/wordpress-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/06\/New-WP_in-text-banner-1024x300.png\" alt=\"\" class=\"wp-image-111781\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/06\/New-WP_in-text-banner-1024x300.png 1024w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/06\/New-WP_in-text-banner-300x88.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/06\/New-WP_in-text-banner-150x44.png 150w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/06\/New-WP_in-text-banner-768x225.png 768w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/06\/New-WP_in-text-banner-1536x450.png 1536w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/06\/New-WP_in-text-banner.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h2 class=\"wp-block-heading\" id=\"h-how-to-create-a-wordpress-theme\">How to Create a WordPress Theme<\/h2><p>After setting up the staging area, follow these steps to create a WordPress theme from scratch using PHP, <a href=\"\/my\/tutorials\/difference-between-html-and-html5\">HTML5<\/a>, and CSS3.<\/p><h3 class=\"wp-block-heading\" id=\"h-1-create-and-store-the-template-files\">1. Create and Store the Template Files<\/h3><p>Creating your own custom theme requires at least two templates. The<strong> index.php<\/strong> file displays content, while <strong>style.css<\/strong> manages the visual theme elements, like fonts.<\/p><p>However, most WordPress themes have additional template files defining the layout of specific website areas, like posts and pages. Here are some of the most common ones:<\/p><ul class=\"wp-block-list\">\n<li><strong>header.php<\/strong> &ndash; contains HTML displayed on top of your WordPress website.<\/li>\n\n\n\n<li><strong>footer.php<\/strong> &ndash; stores HTML that goes at the bottom of your website.<\/li>\n\n\n\n<li><strong>sidebar.php<\/strong> &ndash; generates sidebar elements.<\/li>\n\n\n\n<li><strong>functions.php<\/strong> &ndash; adds functionality to the theme, like <a href=\"\/my\/tutorials\/wordpress-widgets\">WordPress widgets<\/a>.<\/li>\n\n\n\n<li><strong>single.php<\/strong> &ndash; displays a single post, including custom types.<\/li>\n\n\n\n<li><strong>page.php<\/strong> &ndash; shows static content of a single page.<\/li>\n<\/ul><p>In this tutorial, we will use all these template files. Follow these steps to create them in the staging site:<\/p><ol class=\"wp-block-list\">\n<li>Log in to hPanel and access your website&rsquo;s <strong>File Manager<\/strong>.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/03\/The-File-Manager-button-in-hPanel-website-managment-dashboard.png\"><img decoding=\"async\" width=\"1024\" height=\"293\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/03\/The-File-Manager-button-in-hPanel-website-managment-dashboard-1024x293.png\" alt=\"The File Manager button in hPanel website managment dashboard\" class=\"wp-image-106346\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-File-Manager-button-in-hPanel-website-managment-dashboard-1024x293.png 1024w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-File-Manager-button-in-hPanel-website-managment-dashboard-300x86.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-File-Manager-button-in-hPanel-website-managment-dashboard-150x43.png 150w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-File-Manager-button-in-hPanel-website-managment-dashboard-768x220.png 768w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-File-Manager-button-in-hPanel-website-managment-dashboard.png 1273w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><ol start=\"2\" class=\"wp-block-list\">\n<li>Navigate to<strong> <\/strong>the WordPress<strong> themes <\/strong>directory by going to <strong>public_html <\/strong>&rarr; <strong>staging<\/strong> &rarr; <strong>wp-content &rarr; themes<\/strong>.<\/li>\n\n\n\n<li>From the sidebar, click <strong>New folder<\/strong>.<\/li>\n\n\n\n<li>Enter your theme name. It should be unique, short, and contain only alphanumeric characters without spaces. Click <strong>Create<\/strong>.<\/li>\n\n\n\n<li>Double-click the folder to open it. Select <strong>New File<\/strong> on the sidebar.<\/li>\n\n\n\n<li>Enter <strong>index.php <\/strong>and click <strong>Create<\/strong>.<\/li>\n\n\n\n<li>Repeat the previous two steps for all your template files. In this tutorial, we will create <strong>style.css<\/strong>, <strong>header.php<\/strong>, <strong>footer.php<\/strong>, <strong>functions.php<\/strong>, <strong>sidebar.php<\/strong>,<strong> single.php<\/strong>, and <strong>page.php<\/strong>.<\/li>\n<\/ol><p>These theme files should be in the same folder within the WordPress installation directory to allow the CMS to load these theme files based on the <a href=\"https:\/\/developer.wordpress.org\/themes\/basics\/template-hierarchy\/\" target=\"_blank\" rel=\"noopener\">template hierarchy<\/a>.<\/p><p>You won&rsquo;t need all these custom templates if your entire website uses the same layout. However, we recommend using them to separate the main code from the additional content to simplify theme customization.<\/p><p>You also need to create JavaScript files in the theme directory if you want dynamic design elements. We won&rsquo;t use them in this tutorial; instead, we will make a folder called<strong> Images<\/strong> to store visual assets like logos.<\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/03\/Content-of-a-new-theme-folder.png\"><img decoding=\"async\" width=\"1024\" height=\"438\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/03\/Content-of-a-new-theme-folder-1024x438.png\" alt=\"Content of a new theme folder\" class=\"wp-image-106347\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/Content-of-a-new-theme-folder-1024x438.png 1024w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/Content-of-a-new-theme-folder-300x128.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/Content-of-a-new-theme-folder-150x64.png 150w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/Content-of-a-new-theme-folder-768x329.png 768w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/Content-of-a-new-theme-folder.png 1488w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><p>Currently, these theme files are empty. We&rsquo;ll add the visual presentation first and set up the layout afterward.<\/p><h3 class=\"wp-block-heading\" id=\"h-2-set-up-the-initial-css-stylesheet\">2. Set Up the Initial CSS Stylesheet<\/h3><p>After creating all the theme template files, we can start writing the code. Begin by adding details to the <strong>style.css<\/strong> stylesheet we made earlier to allow WordPress to recognize its content.<\/p><p>These details are information that will show up in the WordPress admin area, like the theme name, author, and description. They are written based on the <a href=\"https:\/\/codex.wordpress.org\/File_Header#Theme\" target=\"_blank\" rel=\"noopener\">WordPress file header<\/a> formatting. Here is an example:<\/p><pre class=\"wp-block-preformatted\">\/*\nTheme Name: My Theme\nAuthor: Hostinger\nAuthor URI: http:\/\/www.hostinger.com\/tutorials\nDescription: My first responsive HTML5 theme\nVersion: 1.0\nLicense: GNU General Public License v3 or later\nLicense URI: http:\/\/www.gnu.org\/licenses\/gpl-3.0.html\n*\/\n<\/pre><p><div><p class=\"important\"><strong>Important!<\/strong> If you wish to make your themes public, the last two lines about license information are mandatory. Otherwise, you can omit them.<\/p><\/div>\n\n\n\n<\/p><p>Click the <strong>disk <\/strong>icon on the top right to save the file. Now, return to hPanel&rsquo;s website management menu &rarr;<strong> WordPress<\/strong> &rarr; <strong>Staging<\/strong>. Click <strong>Manage Staging <\/strong>on your test environment and select <strong>Staging Admin Panel<\/strong>.<\/p><p>Navigate to the sidebar &rarr; <strong>Appearance<\/strong> &rarr; <strong>Themes<\/strong>, and you will see the base of your theme.<\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/03\/An-empty-theme-appears-on-the-WordPress-Themes-menu.png\"><img decoding=\"async\" width=\"1024\" height=\"323\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/03\/An-empty-theme-appears-on-the-WordPress-Themes-menu-1024x323.png\" alt=\"An empty theme appears on the WordPress Themes menu\" class=\"wp-image-106348\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/An-empty-theme-appears-on-the-WordPress-Themes-menu.png 1024w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/An-empty-theme-appears-on-the-WordPress-Themes-menu-300x95.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/An-empty-theme-appears-on-the-WordPress-Themes-menu-150x47.png 150w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/An-empty-theme-appears-on-the-WordPress-Themes-menu-768x242.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><p>Let&rsquo;s add the visual design to make the theme more interesting. Open the stylesheet file and write your CSS code under the header. For example, we&rsquo;ll add the following to change the background color:<\/p><pre class=\"wp-block-preformatted\">* {\n  box-sizing: border-box;\n}\nbody {\n    background-color: #f9f9f9;\n    font-family: Helvetica;\n}\n<\/pre><p>Let&rsquo;s break down the code to understand it. The snippet starts with an asterisk (<strong>*<\/strong>) to select all HTML elements and apply the styling within the first curly bracket pair. In this case, we add a <a href=\"https:\/\/www.w3schools.com\/css\/css_boxmodel.asp\" target=\"_blank\" rel=\"noopener\">CSS box model<\/a> that houses the content, padding, and border.<\/p><p>Meanwhile, the second styling sets the background color and default font for all HTML content within the <strong>&lt;body&gt;&lt;\/body&gt;<\/strong> tags.<\/p><p>Currently, you won&rsquo;t see any changes since the HTML content is missing. We will include more CSS code after adding elements and building the theme&rsquo;s structure.<\/p><h3 class=\"wp-block-heading\" id=\"h-3-make-the-wordpress-theme-functional\">3. Make the WordPress Theme Functional<\/h3><p>Now that your WordPress theme shows up in the admin dashboard, it&rsquo;s time to create the structure and functions. We will do so by adding code to the <strong>functions.php<\/strong> and <strong>sidebar.php<\/strong> files.<\/p><p><strong>functions.php<\/strong><\/p><p>Due to inconsistent <a href=\"\/my\/tutorials\/padding-vs-margin\">margins and padding<\/a> settings, several web browsers might display your WordPress theme differently. To ensure it shows properly, link the<strong> <\/strong><a href=\"https:\/\/necolas.github.io\/normalize.css\/\" target=\"_blank\" rel=\"noopener\">normalize.css<\/a> file to <strong>functions.php<\/strong>.<\/p><p>The<strong> normalize.css<\/strong> template is a premade stylesheet that provides a basis for your CSS code, allowing it to load consistently across different browsers. To add it, insert the normalization function into <strong>functions.php<\/strong>:<\/p><pre class=\"wp-block-preformatted\">&lt;?php\n\/\/ This function enqueues the Normalize.css for use. The first parameter is a name for the stylesheet, the second is the URL. Here we\n\/\/ use an online version of the css file.\nfunction add_normalize_CSS() {\n   wp_enqueue_style( 'normalize-styles', \"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/normalize\/7.0.0\/normalize.min.css\");\n}\n\nadd_action('wp_enqueue_scripts', 'add_normalize_CSS');\n<\/pre><p>This code will prompt WordPress to pick the<strong> normalize.css<\/strong> file from the <a href=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/normalize\/7.0.0\/normalize.min.css\" target=\"_blank\" rel=\"noopener\">attached source<\/a> URL.<\/p><p>Next, add a function to enable the <strong>widget area<\/strong> or <strong>sidebar<\/strong>. A widget is a modular extension that lets you add specific features to different sections of your WordPress website. To enable it, add the following after the previous snippet:<\/p><pre class=\"wp-block-preformatted\">\/\/ Register a new sidebar simply named 'sidebar'\nfunction add_widget_support() {\n               register_sidebar( array(\n                               'name'          =&gt; 'Sidebar',\n                               'id'            =&gt; 'sidebar',\n                               'before_widget' =&gt; '&lt;div&gt;',\n                               'after_widget'  =&gt; '&lt;\/div&gt;',\n                               'before_title'  =&gt; '&lt;h2&gt;',\n                               'after_title'   =&gt; '&lt;\/h2&gt;',\n               ) );\n}\n\/\/ Hook the widget initiation and run our function\nadd_action( 'widgets_init', 'add_widget_support' );\n<\/pre><p>Now, let&rsquo;s activate the theme by going to the <strong>Appearance<\/strong> &rarr; <strong>Themes<\/strong> and clicking <strong>Activate<\/strong>. You should see the <strong>Widgets<\/strong> menu under the<strong> Appearance<\/strong> tab, where you can add or remove widgets from your website.<\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/03\/The-Widgets-menu-of-a-newly-created-theme.png\"><img decoding=\"async\" width=\"1024\" height=\"405\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/03\/The-Widgets-menu-of-a-newly-created-theme-1024x405.png\" alt=\"The Widgets menu of a newly created theme\" class=\"wp-image-106351\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-Widgets-menu-of-a-newly-created-theme.png 1024w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-Widgets-menu-of-a-newly-created-theme-300x119.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-Widgets-menu-of-a-newly-created-theme-150x59.png 150w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-Widgets-menu-of-a-newly-created-theme-768x304.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><p>The code contains an <a href=\"\/my\/tutorials\/what-are-wordpress-hooks\/\">action hook<\/a> &ndash; a PHP function that loads code from another file to modify WordPress settings and features without altering the core. We&rsquo;ll discuss this terminology further in the later section.<\/p><p>Lastly, add the following code to enable the function for inserting a custom navigation menu:<\/p><pre class=\"wp-block-preformatted\">\/\/ Register a new navigation menu\nfunction add_Main_Nav() {\n  register_nav_menu('header-menu',__( 'Header Menu' ));\n}\n\/\/ Hook to the init action hook, run our navigation menu function\nadd_action( 'init', 'add_Main_Nav' );\n<\/pre><p>It will show the <strong>Menus <\/strong>button under the <strong>Appearance<\/strong> menu. Remember to save the changes by clicking the<strong> disk<\/strong> button in the <strong>File Manager<\/strong> code editor after adding new code.<\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/03\/The-save-button-in-File-Manager-code-editor.png\"><img decoding=\"async\" width=\"1024\" height=\"226\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/03\/The-save-button-in-File-Manager-code-editor-1024x226.png\" alt=\"The save button in File Manager code editor\" class=\"wp-image-106352\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-save-button-in-File-Manager-code-editor-1024x226.png 1024w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-save-button-in-File-Manager-code-editor-300x66.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-save-button-in-File-Manager-code-editor-150x33.png 150w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-save-button-in-File-Manager-code-editor-768x170.png 768w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-save-button-in-File-Manager-code-editor.png 1397w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><p>There are various other functions to insert. For example, WordPress site owners commonly add a featured image and post thumbnails.<\/p><p><strong>sidebar.php<\/strong><\/p><p>Next, we&rsquo;ll create the WordPress theme&rsquo;s sidebar to display the widgets using the <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/get_sidebar\/\" target=\"_blank\" rel=\"noopener\">get_sidebar()<strong> function<\/strong><\/a>. Insert the code below into the<strong> sidebar.php<\/strong> file and save the changes.<\/p><pre class=\"wp-block-preformatted\">&lt;?php if ( is_active_sidebar( 'sidebar' ) ) : ?&gt;\n  &lt;aside id=\"primary-sidebar\" class=\"primary-sidebar widget-area\" role=\"complementary\"&gt;\n    &lt;?php dynamic_sidebar( 'sidebar' ); ?&gt;\n  &lt;\/aside&gt;\n&lt;?php endif; ?&gt;\n<\/pre><p>In the code, the<strong> if<\/strong> statement checks whether WordPress already displays a sidebar. If not, it will show the widgets you have added from the <strong>Widgets<\/strong> menu under the<strong> Appearance <\/strong>tab.<\/p><h3 class=\"wp-block-heading\" id=\"h-4-build-a-layout-for-your-custom-theme\">4. Build a Layout for Your Custom Theme<\/h3><p>After adding the sidebar and CSS normalization functions, let&rsquo;s create the layout of your WordPress theme. By the end of this step, the website structure will start to take shape.<\/p><p>In addition to<strong> index.php<\/strong>, we will modify the <strong>header.php<\/strong>,<strong> footer.php<\/strong>, <strong>single.php<\/strong>,<strong> page.php<\/strong>, and <strong>style.php<\/strong> files to give each web page a dedicated layout.<\/p><p><strong>header.php<\/strong><\/p><p>The header template file defines the top area of your web page. Start your code with the following:<\/p><pre class=\"wp-block-preformatted\">&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\n<\/pre><p>The snippet allows the header of your WordPress custom theme to adjust its size automatically based on the screen size using <strong>responsive design<\/strong>. We&rsquo;ll explain this concept in-depth later.<\/p><p>Next, add the following:<\/p><pre class=\"wp-block-preformatted\">&lt;!DOCTYPE html&gt;\n&lt;html &lt;?php language_attributes(); ?&gt;\n<\/pre><p>The<strong> DOCTYPE <\/strong>declaration tells the web browser the file type of your header template. Meanwhile, the <strong>language_attributes() <\/strong>function specifies HTML as the document&rsquo;s primary coding language.<\/p><p>Then, add the <strong>&lt;head&gt;&lt;\/head&gt;<\/strong> HTML tags, which contain the document metadata, like the web page title, default character set, responsive design viewport, and the linked stylesheet. All these details are enclosed with different tags.<\/p><pre class=\"wp-block-preformatted\"> &lt;head&gt;\n   &lt;title&gt;&lt;?php bloginfo('name'); ?&gt; &amp;raquo; &lt;?php is_front_page() ? bloginfo('description') : wp_title(''); ?&gt;&lt;\/title&gt;\n   &lt;meta charset=\"&lt;?php bloginfo( 'charset' ); ?&gt;\"&gt;\n   &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\n   &lt;link rel=\"stylesheet\" href=\"&lt;?php bloginfo('stylesheet_url'); ?&gt;\"&gt;\n   &lt;?php wp_head(); ?&gt;\n &lt;\/head&gt;\n<\/pre><p>Next, we create the HTML document&rsquo;s body section and use the<strong> body_class<\/strong> function to automatically assign a class to the <strong>&lt;body&gt;<\/strong> tag for styling.<\/p><pre class=\"wp-block-preformatted\"> &lt;body &lt;?php body_class(); ?&gt;&gt;<\/pre><p>Add the header, which we will classify as the <strong>my-logo <\/strong>class. Then, we use <strong>&lt;h1&gt;&lt;\/h1&gt;<\/strong> tags to show the logo in the <strong>Image<\/strong> folder as the main heading and anchor for the website&rsquo;s URL.<\/p><pre class=\"wp-block-preformatted\">&lt;header class=\"my-logo\"&gt;\n    &lt;h1&gt;&lt;a href=\"&lt;?php echo esc_url( home_url( '\/' ) ); ?&gt;\"&gt;&lt;img src=\"&lt;?php echo get_template_directory_uri(); ?&gt;\/Images\/logo.png\" alt=\"Site Logo\" width=\"50px\" height=\"50px\"&gt;&lt;\/a&gt;&lt;\/h1&gt;\n&lt;\/header&gt;\n<\/pre><p>Lastly, add the following to insert a navigation menu in the theme&rsquo;s header:<\/p><pre class=\"wp-block-preformatted\"> &lt;?php wp_nav_menu( array( 'header-menu' =&gt; 'header-menu' ) ); ?&gt;\n<\/pre><p><strong>index.php<\/strong><\/p><p>The<strong> index.php<\/strong> file defines the homepage structure and serves as the default layout if other page templates are unavailable.<\/p><p>If you have different layouts for the header, sidebar, and footer, add the <a href=\"https:\/\/codex.wordpress.org\/Template_Tags\" target=\"_blank\" rel=\"noopener\">template tags<\/a> to call their code into<strong> index.php<\/strong>. For example, use <strong>get_header<\/strong> to link the header, and so on.<\/p><p>To section your web page, use HTML5 semantic elements like <strong>&lt;head&gt;<\/strong> and <strong>&lt;section&gt;<\/strong>. If you want to apply the CSS stylesheet to them, add the class like the following:<\/p><pre class=\"wp-block-preformatted\">&lt;head class=\"class-name\"&gt;\n<\/pre><p><div><p class=\"important\"><strong>Important!<\/strong> Header tags can appear multiple times and don&rsquo;t necessarily refer to the page header. Semantic elements should have a header if there&rsquo;s text inside h1, h2, etc.<\/p><\/div>\n\n\n\n<\/p><p>Here&rsquo;s an example of code in the <strong>index.php<\/strong> file containing template tags and semantic elements:<\/p><pre class=\"wp-block-preformatted\">&lt;?php get_header(); ?&gt;\n&lt;main class=\"wrap\"&gt;\n  &lt;section class=\"content-area content-thin\"&gt;\n&lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt;\n      &lt;article class=\"article-loop\"&gt;\n        &lt;header&gt;\n          &lt;h2&gt;&lt;a href=\"&lt;?php the_permalink(); ?&gt;\" title=\"&lt;?php the_title_attribute(); ?&gt;\"&gt;&lt;?php the_title(); ?&gt;&lt;\/a&gt;&lt;\/h2&gt;\n          By: &lt;?php the_author(); ?&gt;\n        &lt;\/header&gt;\n        &lt;?php the_excerpt(); ?&gt;\n      &lt;\/article&gt;\n&lt;?php endwhile; else : ?&gt;\n      &lt;article&gt;\n        &lt;p&gt;Sorry, no posts were found!&lt;\/p&gt;\n      &lt;\/article&gt;\n&lt;?php endif; ?&gt;\n  &lt;\/section&gt;&lt;?php get_sidebar(); ?&gt;\n&lt;\/main&gt;\n&lt;?php get_footer(); ?&gt;\n<\/pre><p>In the code above, we also added a <a href=\"https:\/\/codex.wordpress.org\/The_Loop\" target=\"_blank\" rel=\"noopener\">WordPress loop<\/a> &ndash; PHP code that retrieves posts from the database and passes them to other functions. It starts at<strong> &lt;?php if ( have_posts() )<\/strong> <strong>: while ( have_posts() ) : the_post(); ?&gt;<\/strong> and ends with <strong>&lt;?php endif; ?&gt;<\/strong>.<\/p><p>The loop contains the following functions to retrieve specific details from the post:<\/p><ul class=\"wp-block-list\">\n<li><strong>&lt;?php the_permalink(); ?&gt;<\/strong> &ndash; outputs the post&rsquo;s actual URL.<\/li>\n\n\n\n<li><strong>&lt;?php the_title_attribute(); ?&gt;<\/strong> &ndash; displays the post title in a format compatible with element attributes.<\/li>\n\n\n\n<li><strong>&lt;?php the_title(); ?&gt;<\/strong> &ndash; shows the post title<\/li>\n\n\n\n<li><strong>&lt;?php the_author(); ?&gt; <\/strong>&ndash; outputs the post&rsquo;s author name.<\/li>\n\n\n\n<li><strong>&lt;?php the_excerpt(); ?&gt;<\/strong> &ndash; extracts the post&rsquo;s excerpt, which will be auto-generated if you don&rsquo;t write one.<\/li>\n<\/ul><p><strong>footer.php<\/strong><\/p><p>The<strong> footer.php <\/strong>file defines content at the bottom of your theme, like copyright information or a sitemap. You can also add the <strong>&lt;body&gt; <\/strong>and <strong>&lt;html&gt;<\/strong> closing tags here if you haven&rsquo;t specified them in <strong>header.php<\/strong>.<\/p><p>Define your footer content with the <strong>&lt;footer&gt;&lt;\/footer&gt;<\/strong> HTML semantic element. For example, we will add copyright information at the bottom.<\/p><p>We&rsquo;ll also add the <a href=\"https:\/\/developer.wordpress.org\/reference\/hooks\/wp_footer\/\" target=\"_blank\" rel=\"noopener\">wp_footer action<\/a> hook to load the <strong>wp_footer function<\/strong>&rsquo;s code in WordPress&rsquo; core or plugins&rsquo; files. Here&rsquo;s how the complete code will look:<\/p><pre class=\"wp-block-preformatted\">&lt;footer&gt;<br>      &lt;p&gt;Copyright &amp;copy; 2025&lt;\/p&gt;<br>    &lt;\/footer&gt;<br>    &lt;?php wp_footer(); ?&gt;<br>  &lt;\/body&gt;<br>&lt;\/html&gt;<br><\/pre><p><strong>single.php<\/strong><\/p><p>The <strong>single.php<\/strong> file determines the layout of all post types in WordPress. In addition to blog entries, it defines <a href=\"\/my\/tutorials\/wordpress-custom-post-types\">custom post types<\/a> like a product page on an online store.<\/p><p>Start the code by calling the header file using the <strong>get_header() <\/strong>function like the following:<\/p><pre class=\"wp-block-preformatted\">&lt;?php get_header(); ?&gt;\n<\/pre><p>Then, add the <strong>&lt;section&gt;&lt;\/section&gt;<\/strong> tags to create the main container and assign a class for styling. Use a WordPress loop to retrieve the post content and display it using <strong>the_content()<\/strong> function.<\/p><p>If the post content isn&rsquo;t available, we&rsquo;ll display an error message. Here&rsquo;s what the complete code will look like:<\/p><pre class=\"wp-block-preformatted\">&lt;main class=\"wrap\"&gt;\n  &lt;section class=\"content-area content-full-width\"&gt;\n&lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt;\n      &lt;article class=\"article-full\"&gt;\n        &lt;header&gt;\n          &lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;\/h2&gt;\n          By: &lt;?php the_author(); ?&gt;\n        &lt;\/header&gt;\n       &lt;?php the_content(); ?&gt;\n      &lt;\/article&gt;\n&lt;?php endwhile; else : ?&gt;\n      &lt;article&gt;\n        &lt;p&gt;Sorry, no post was found!&lt;\/p&gt;\n      &lt;\/article&gt;\n&lt;?php endif; ?&gt;\n  &lt;\/section&gt;\n&lt;\/main&gt;\n&lt;?php get_footer(); ?&gt;\n<\/pre><p>Unlike other template files, we don&rsquo;t add the <strong>get_sidebar()<\/strong> function to omit the sidebar and widgets from all posts.<\/p><p><strong>page.php<\/strong><\/p><p>Areas like landing pages contain everlasting content that rarely changes. Instead of <strong>single.php<\/strong>, they will inherit the layout from <strong>index.php<\/strong> if dedicated page templates<strong> <\/strong>are missing.<\/p><p>We will use code similar to <strong>single.php<\/strong> but with several adjustments to distinguish website pages from posts. In addition to inserting a sidebar, we will make the content area smaller. Here&rsquo;s how the code will look:<\/p><pre class=\"wp-block-preformatted\">&lt;?php get_header(); ?&gt;\n&lt;main class=\"wrap\"&gt;\n  &lt;section class=\"content-area content-thin\"&gt;\n&lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt;\n      &lt;article class=\"article-full\"&gt;\n        &lt;header&gt;\n          &lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;\/h2&gt;\n          By: &lt;?php the_author(); ?&gt;\n        &lt;\/header&gt;\n        &lt;?php the_content(); ?&gt;\n      &lt;\/article&gt;\n&lt;?php endwhile; else : ?&gt;\n      &lt;article&gt;\n        &lt;p&gt;Sorry, no page content was found!&lt;\/p&gt;\n      &lt;\/article&gt;\n&lt;?php endif; ?&gt;\n  &lt;\/section&gt;&lt;?php get_sidebar(); ?&gt;\n&lt;\/main&gt;\n&lt;?php get_footer(); ?&gt;\n<\/pre><p>Although we use the same loop, this code will iterate through pages instead of posts since we put it in the <strong>page.php<\/strong> file.<\/p><p>Currently, your custom WordPress theme has a layout and content. However, it will show plain text and a logo if you access the staging website since you haven&rsquo;t added any styling.<\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/03\/The-new-theme-appearance-without-styling.png\"><img decoding=\"async\" width=\"1024\" height=\"425\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/03\/The-new-theme-appearance-without-styling-1024x425.png\" alt=\"The new theme appearance without styling\" class=\"wp-image-106357\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-new-theme-appearance-without-styling-1536x637.png 1024w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-new-theme-appearance-without-styling-300x124.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-new-theme-appearance-without-styling-150x62.png 150w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-new-theme-appearance-without-styling-768x318.png 768w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-new-theme-appearance-without-styling.png 1577w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><p>Instead of opening PHP template files via File Manager, you can use <strong>File Theme Editor <\/strong>to add or modify their code. Access it from the<strong> Appearance<\/strong> menu in the WordPress admin dashboard.<\/p><h3 class=\"wp-block-heading\" id=\"h-5-improve-your-design-on-the-css-stylesheet\">5. Improve Your Design on the CSS Stylesheet<\/h3><p>After adding the HTML elements and assigning them classes, return to your stylesheet to customize their design. Begin by adding the following into <strong>style.css <\/strong>to modify the logo&rsquo;s size, padding, and color:<\/p><pre class=\"wp-block-preformatted\">.my-logo,\nfooter {\n  width: 100%;\n  padding-left: 1%;\n  margin-bottom: 8px;\n  background-color: #78baff;\n  border: 1px solid #78baff;\n}\n<\/pre><p>Then, add the following to style sections in your theme layout. We&rsquo;ll customize the <strong>h1 anchor<\/strong>, <strong>article<\/strong>, and <strong>footer<\/strong>:<\/p><pre class=\"wp-block-preformatted\">body &gt; header &gt; h1 &gt; a {\n  color: #ffffff;\n  font-weight: 400;\n}\n\narticle &gt; header {\n}\n\nfooter {\n  margin-top: 4px;\n}\n\na {\n  text-decoration: none;\n}\n\n\/* 'Margin: 0 auto' centers block content on the page *\/\n.wrap {\n  width: 99%;\n  margin: 0 auto;\n}\n<\/pre><p>Lastly, assign the styling to other elements like the content area and sidebar by adding the following code snippets:<\/p><pre class=\"wp-block-preformatted\">.content-area {\n  display: inline-block;\n}\n\n.content-thin {\n    width: 70%;\n}\n\n.content-full-width {\n    width: 100%;\n}\n\n.content-area,\n.primary-sidebar {\n  display: inline-block;\n}\n\n.primary-sidebar {\n  width: 25%;\n  padding: 1%;\n  vertical-align: top;\n  background-color: #ececec;\n}\n\n.article-loop {\n    width: 45%;\n    text-align: left;\n    margin: 5px;\n    padding: 10px;\n}\n\n.article-full {\n  width: 99%;\n  padding: 1%;\n}\n\n.article-loop,\n.article-full {\n  display: inline-block;\n  vertical-align: top;\n  background-color: #FFF;\n  border-radius: 4px;\n  margin-bottom: 4px;\n}\n<\/pre><p>Once you apply your new theme, your staging website should look like this:<\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/03\/The-finished-WordPress-theme-appearance.png\"><img decoding=\"async\" width=\"1024\" height=\"422\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/03\/The-finished-WordPress-theme-appearance-1024x422.png\" alt=\" The finished WordPress theme appearance\" class=\"wp-image-106358\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-finished-WordPress-theme-appearance.png 1024w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-finished-WordPress-theme-appearance-300x124.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-finished-WordPress-theme-appearance-150x62.png 150w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-finished-WordPress-theme-appearance-768x317.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><p>To modify the stylesheet, you can <a href=\"\/my\/tutorials\/wordpress-custom-css\">add WordPress custom CSS<\/a> via the theme editor. Access the feature by going to <strong>Appearance<\/strong> &rarr; <strong>Themes<\/strong> &rarr; <strong>Customize<\/strong> &rarr; <strong>Additional CSS<\/strong> on the sidebar.<\/p><p><div><p class=\"important\"><strong>Important!<\/strong> Since we are developing a classic theme, you can&rsquo;t use <strong>WordPress Full Site Editing<\/strong> by default. Use a theme builder plugin to customize it.<\/p><\/div>\n\n\n\n<\/p><h3 class=\"wp-block-heading\" id=\"h-6-test-and-deploy-your-theme\">6. Test and Deploy Your Theme<\/h3><p>Before deploying your new custom theme, let&rsquo;s activate it in your staging WordPress site to check if it displays and works properly.<\/p><p>Go to your staging area admin dashboard and activate your new theme via the <strong>Themes<\/strong> menu. Then, access the test website by clicking the <strong>Visit Site <\/strong>button at the top of the admin bar.<\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/03\/the-visit-site-button-in-staging-site-admin-panel.png\"><img decoding=\"async\" width=\"776\" height=\"115\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/03\/the-visit-site-button-in-staging-site-admin-panel.png\" alt=\"The Visit Site button in the staging site admin panel\" class=\"wp-image-106360\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/the-visit-site-button-in-staging-site-admin-panel.png 776w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/the-visit-site-button-in-staging-site-admin-panel-300x44.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/the-visit-site-button-in-staging-site-admin-panel-150x22.png 150w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/the-visit-site-button-in-staging-site-admin-panel-768x114.png 768w\" sizes=\"(max-width: 776px) 100vw, 776px\" \/><\/a><\/figure><\/div><p>After checking the visual appearances and layouts, deploy the theme into your live site. To do so, return to the staging area&rsquo;s <strong>File Manager<\/strong>, click your theme folder, and select the <strong>download<\/strong> button on the top bar. Download it as a <strong>ZIP <\/strong>file.<\/p><p>Extract the folder to your local computer and upload it to your live site&rsquo;s <strong>\/wp-content\/themes<\/strong> directory via <strong>File Manager<\/strong>. Activate the theme via the WordPress admin dashboard.<\/p><h2 class=\"wp-block-heading\" id=\"h-essential-concepts-in-wordpress-theme-development\">Essential Concepts in WordPress Theme Development<\/h2><p>After creating your own theme, you might want to modify its features and appearance later. To help you get started, we will explain essential design and functionality concepts in WordPress theme development.<\/p><h3 class=\"wp-block-heading\" id=\"h-media-queries-and-responsive-design\">Media Queries and Responsive Design<\/h3><p>Website visitors&rsquo; screens vary in resolution, size, and orientation. If you only develop the theme for desktop, it won&rsquo;t display and function correctly on other devices like mobile phones.<\/p><p>Applying responsive design ensures your theme works properly regardless of the screen size. It lets the website adjust its layout, content placement, and element sizes automatically by detecting the devices&rsquo; display type.<\/p><p>To enable responsive theme design, add <strong>CSS media queries<\/strong> to define the content presentation when the viewport alters. They use percentages to determine the layout and size relative to the screen.<\/p><p>For example, each section in the two-column theme design will always occupy 50% regardless of the resolution and orientation. There are <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/@media\" target=\"_blank\" rel=\"noopener\">several CSS properties<\/a> for media queries, but some of the common ones are:<\/p><ul class=\"wp-block-list\">\n<li><strong>max-width<\/strong> &ndash; defines the maximum width of the browser&rsquo;s viewable area.<\/li>\n\n\n\n<li><strong>min-width<\/strong> &ndash; determines the minimum width of the visible area.<\/li>\n\n\n\n<li><strong>orientation<\/strong> &ndash; checks whether the screen is in a portrait or a landscape mode.<\/li>\n<\/ul><p>We recommend adding the media queries at the bottom and assigning classes for cleaner code organization and simpler theme customization.<\/p><p>For instance, add the following media query to automatically adjust the size of the previously created theme&rsquo;s main content and sidebar:<\/p><pre class=\"wp-block-preformatted\">@media screen and (max-width: 400px) {\n  .content-area,\n  .primary-sidebar {\n    width: 80%;\n  }\n}\n<\/pre><p>This rule applies to screens and browser windows with a maximum width of <strong>400 <\/strong>pixels. The selected elements, namely <strong>content-area<\/strong> and <strong>primary-sidebar<\/strong>, will show <strong>80%<\/strong> of their original size if the viewport is within the specified dimension.<\/p><p>You might need additional rules for other screen sizes and orientations to ensure your content always displays correctly. For instance, set a condition when the content shows at 100%:<\/p><pre class=\"wp-block-preformatted\">@media screen and (max-width: 800px) {\n  .content-area,\n  .primary-sidebar {\n    width: 100%;\n  }\n}\n<\/pre><h3 class=\"wp-block-heading\" id=\"h-template-tags\">Template Tags<\/h3><p>Template tags are PHP functions that let you easily link files and simplify complex database queries. Instead of writing long code, <a href=\"\/my\/tutorials\/how-to-become-wordpress-developer\">WordPress developers<\/a> can achieve such tasks using a single line of script.<\/p><p>To apply a template on a specific page, add the tag to the corresponding file. For instance, to show the<strong> footer<\/strong> only on the home page, add <strong>get_footer<\/strong> at the bottom of <strong>home.php<\/strong> and not <strong>page.php<\/strong>.<\/p><p>While some tags are optional if you don&rsquo;t use the template file, others are essential to ensure WordPress loops work correctly. They retrieve post information from the database, allowing the loop to iterate and pass the data.<\/p><p>To link a template file, here are some of the most commonly used tags:<\/p><ul class=\"wp-block-list\">\n<li><strong>get_header()<\/strong> &ndash; includes the <strong>header.php<\/strong> template.<\/li>\n\n\n\n<li><strong>get_sidebar()<\/strong> &ndash; calls the <strong>sidebar.php<\/strong> template.<\/li>\n\n\n\n<li><strong>get_footer()<\/strong> &ndash; links the <strong>footer.php<\/strong> template.<\/li>\n\n\n\n<li><strong>get_search_form()<\/strong> &ndash; includes the <strong>searchform.php<\/strong> template.<\/li>\n<\/ul><p>Meanwhile, the following template tags display information from the WordPress database:<\/p><ul class=\"wp-block-list\">\n<li><strong>bloginfo()<\/strong> &ndash; displays information requested in the parameter, such as <strong>bloginfo(&ldquo;name&rdquo;) <\/strong>that shows your website&rsquo;s name.<\/li>\n\n\n\n<li><strong>single_post_title()<\/strong> &ndash; presents the title of the currently viewed post when used in the <strong>single.php<\/strong> file.<\/li>\n\n\n\n<li><strong>the_author()<\/strong> &ndash; shows the author of the currently viewed post.<\/li>\n\n\n\n<li><strong>the_content()<\/strong> &ndash; outputs the main text of a post or page.<\/li>\n\n\n\n<li><strong>the_excerpt() <\/strong>&ndash; displays an excerpt of any posts or pages.<\/li>\n<\/ul><h3 class=\"wp-block-heading\" id=\"h-wordpress-loop\">WordPress Loop<\/h3><p>A WordPress loop is code that iterates through posts, retrieves their data, and passes it into other functions. Its basic functionality is fetching content from the database and displaying it to the front end.<\/p><p>In WordPress theme development, the loop is essential for displaying posts dynamically. Otherwise, you are limited to static content since your template files don&rsquo;t have the latest information from the database.<\/p><p>The loop goes into the<strong> index.php<\/strong> file and other templates that display post content. It always starts with the <strong>if <\/strong>statement, like the following:<\/p><pre class=\"wp-block-preformatted\">&lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt;\n<\/pre><p>Then, specify the template tags, HTML, or PHP functions to modify the retrieved data if it exists. For example, use<strong> the_content()<\/strong> to show a single post&rsquo;s full content or <strong>the_excerpt()<\/strong> to list the shorter version.<\/p><p>In our previous <strong>page.php<\/strong>, we display the page information as the main content using the following code:<\/p><pre class=\"wp-block-preformatted\">&lt;article class=\"article-full\"&gt;\n        &lt;header&gt;\n          &lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;\/h2&gt;\n          By: &lt;?php the_author(); ?&gt;\n        &lt;\/header&gt;\n        &lt;?php the_content(); ?&gt;\n      &lt;\/article&gt;\n<\/pre><p>The WordPress loop ends with the <strong>else <\/strong>statement, specifying the condition to apply if the queried data doesn&rsquo;t exist. For example, it will show an error message:<\/p><pre class=\"wp-block-preformatted\">&lt;?php endwhile; else : ?&gt;\n   &lt;p&gt;&lt;?php _e( 'Sorry, no pages matched your criteria.' ); ?&gt;&lt;\/p&gt;\n&lt;?php endif; ?&gt;\n<\/pre><h3 class=\"wp-block-heading\" id=\"h-action-hooks\">Action Hooks<\/h3><p><a href=\"\/my\/tutorials\/what-are-wordpress-hooks\/\">Hooks<\/a> are PHP functions that let you manipulate the default WordPress feature without editing the core files. Depending on the purpose, there are two types of hook &ndash; <strong>action<\/strong> and <strong>filter<\/strong>.<\/p><p>Filter hooks are used to modify existing code in <strong>function.php<\/strong> and output the altered data to the user. Meanwhile, the action ones are for creating new functions that run at a specific time.<\/p><p>In addition to the core files, you can use hooks to attach functions from WordPress plugins to your theme. It ensures compatibility between different software in the content management system (CMS) environment for optimal stability.<\/p><p>Moreover, hooks let you organize your code in separate files to simplify modifications, updates, and debugging. You can also use them to add more features, like enabling the built-in WordPress customizer or site editor for block themes.<\/p><p>In our newly created theme, we use an action hook in the <strong>header.php<\/strong> file to fetch the default WordPress HTML header and insert it in your code:<\/p><pre class=\"wp-block-preformatted\">&lt;?php wp_head(); ?&gt;\n &lt;\/head&gt;\n<\/pre><p>Meanwhile, the following <strong>wp_footer() <\/strong>action hook in your footer template includes WordPress&rsquo; default code and run functions defined in plugins:<\/p><pre class=\"wp-block-preformatted\">  &lt;?php wp_footer(); ?&gt;\n  &lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre><p>If your theme doesn&rsquo;t include hooks, important source codes won&rsquo;t load, and plugins won&rsquo;t function correctly. For example, a missing <strong>wp_footer()<\/strong> might disable the WordPress admin bar since it is attached to the action hook.<\/p><h2 class=\"wp-block-heading\" id=\"h-creating-a-wordpress-theme-best-practices\">Creating a WordPress Theme Best Practices<\/h2><p>To ensure your WordPress theme performance and integrity, consider the following best practices during development:<\/p><h3 class=\"wp-block-heading\" id=\"h-validate-your-theme-code-and-files\">Validate Your Theme Code and Files<\/h3><p>Check your new theme to ensure it adheres to the latest <a href=\"https:\/\/make.wordpress.org\/themes\/handbook\/review\/\" target=\"_blank\" rel=\"noopener\">WordPress review standards<\/a>. In addition to verifying its functionality, code validation helps catch issues that might affect security, compatibility, licensing, and quality.<\/p><p>The easiest way to do so is by using a plugin like <a href=\"https:\/\/wordpress.org\/plugins\/theme-check\/\" target=\"_blank\" rel=\"noopener\">Theme Check<\/a>. We recommend running the test regularly after making changes to quickly catch potential problems.<\/p><h3 class=\"wp-block-heading\" id=\"h-test-your-theme-on-different-devices-and-browsers\">Test Your Theme on Different Devices and Browsers<\/h3><p>To ensure your WordPress theme&rsquo;s media query rules work correctly on different viewports, access the website on different devices.<\/p><p>You can simulate different screen sizes using your web browser&rsquo;s device toolbar. Google Chrome users can access it by pressing <strong>Ctrl + Shift + C <\/strong>and then <strong>Ctrl + Shift + M<\/strong>. Adjust the resolution and aspect ratio from the top bar.<\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/03\/The-device-toolbar-feature-in-Google-Chrome.png\"><img decoding=\"async\" width=\"1024\" height=\"628\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/03\/The-device-toolbar-feature-in-Google-Chrome-1024x628.png\" alt=\"The device toolbar feature in Google Chrome\" class=\"wp-image-106364\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-device-toolbar-feature-in-Google-Chrome-1024x628.png 1024w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-device-toolbar-feature-in-Google-Chrome-300x184.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-device-toolbar-feature-in-Google-Chrome-150x92.png 150w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-device-toolbar-feature-in-Google-Chrome-768x471.png 768w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/03\/The-device-toolbar-feature-in-Google-Chrome.png 1388w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><p>In addition to testing on different devices, test your WordPress theme on other web browsers since they might render CSS and HTML differently, leading to errors that can hurt the user experience.<\/p><h3 class=\"wp-block-heading\" id=\"h-leverage-a-theme-template\">Leverage a Theme Template<\/h3><p>Use a starter theme to simplify the development process. Instead of writing code from scratch, you only need to add additional styling and features based on your needs.<\/p><p>A theme template usually adheres to WordPress coding standards, providing a robust base theme for your development. Some also have a large community support and knowledge base for easier troubleshooting.<\/p><p>Since there are many starter themes, we recommend a free one from a reputable developer like <a href=\"https:\/\/wpastra.com\/\" target=\"_blank\" rel=\"noopener\">Astra<\/a> and <a href=\"https:\/\/underscores.me\/\" target=\"_blank\" rel=\"noopener\">Underscores<\/a>.<\/p><h3 class=\"wp-block-heading\" id=\"h-minify-and-optimize-your-code\">Minify and Optimize Your Code<\/h3><p>When building WordPress themes from scratch, keep the code clean to reduce the file size. It allows web browsers to render your theme more quickly, ensuring optimal website speed.<\/p><p>To further improve the page load time, use tools like <a href=\"https:\/\/www.minifier.org\/\" target=\"_blank\" rel=\"noopener\">Minifier<\/a> to reduce the size of your PHP, CSS, and JavaScript files. This process removes additional characters that don&rsquo;t affect the code functionality, like whitespaces.<\/p><p>Before <a href=\"\/my\/tutorials\/website\/improving-website-performance-minifying-css-html-and-javascript\">minifying your code<\/a>, back up the original files since the result might be difficult to read, complicating debugging or maintenance.<\/p><p>Also, <a href=\"\/my\/tutorials\/how-to-create-wordpress-child-theme\">create child themes<\/a> &ndash; sub-themes that let you add new functions or styling without affecting the main template files. They help prevent misconfigurations and allow you to revert changes easily.<\/p><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>Creating a custom WordPress theme from scratch allows you to make your website more unique and personalized. You can choose only the necessary features, minimizing code bloat to improve page load speed.<\/p><p>In this article, we have explained how to create your own theme for a WordPress website from scratch. After setting up a staging area, follow these steps:<\/p><ol class=\"wp-block-list\">\n<li>Create<strong> index.php<\/strong>,<strong> style.css<\/strong>, and other template files in your staging area&rsquo;s theme folder inside the WordPress<strong> themes<\/strong> directory.<\/li>\n\n\n\n<li>Set up the initial CSS stylesheet by adding the theme developer information and background color.<\/li>\n\n\n\n<li>Make your WordPress theme functional by adding a sidebar in the<strong> functions.php<\/strong> and <strong>sidebar.php<\/strong>.<\/li>\n\n\n\n<li>Build your WordPress theme layout by sectioning the <strong>index.php<\/strong> and other template files using HTML tags.<\/li>\n\n\n\n<li>Improve your theme design by adding CSS to each class via the stylesheet.<\/li>\n\n\n\n<li>Test your custom theme on the staging area and push the files to the live environment once finished.<\/li>\n<\/ol><p>Apply the responsive design to your WordPress theme to ensure it displays properly across all screen sizes. Also, configure the template tags, WordPress loops, and action hooks correctly to maintain compatibility with other software within the CMS.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-create-a-wordpress-theme-faq\">How to Create a WordPress Theme FAQ<\/h2><p>To help deepen your understanding, this section will answer several commonly asked questions about how to make a WordPress theme.<\/p><div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1711428220695\"><h3 class=\"schema-faq-question\">Is It Hard to Create Your Own WordPress Theme?<\/h3> <p class=\"schema-faq-answer\">It depends on the complexity of the theme you want to create. A basic WordPress theme requires at least two files written in HTML, CSS, and PHP. A feature-packed one is more complicated due to extra programming languages and code. Instead of writing code from scratch, use a basic structure from an existing WordPress theme to make the process easier.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1711428239389\"><h3 class=\"schema-faq-question\">Can You Make Money From WordPress Themes?<\/h3> <p class=\"schema-faq-answer\">Yes, there are various WordPress community marketplaces for selling your own themes, like <a href=\"https:\/\/themeforest.net\/\" target=\"_blank\" rel=\"noopener\">ThemeForest<\/a> and <a href=\"https:\/\/codecanyon.net\/\" target=\"_blank\" rel=\"noopener\">CodeCanyon<\/a>. On average, premium theme developers sell their products at <a href=\"https:\/\/www.codeinwp.com\/blog\/wordpress-theme-cost-analysis\/\" target=\"_blank\" rel=\"noopener\">$59 per license<\/a>.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1711428256223\"><h3 class=\"schema-faq-question\">How Long Does It Take to Build a WordPress Theme?<\/h3> <p class=\"schema-faq-answer\">It takes around two weeks or more, depending on the complexity and features. If you&rsquo;re a beginner, it&rsquo;s normal to require more time since you&rsquo;re also learning web development as you go.<\/p> <\/div> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>While you can always install a pre-made WordPress theme, creating a custom one makes your website more unique. With a custom theme written in popular coding languages like PHP, HTML, and CSS, you can also select specific features or elements based on your needs to improve site performance. Fortunately, creating a WordPress theme from scratch [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/my\/tutorials\/create-wordpress-theme-html5\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":72,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to Create a WordPress Theme in 6 Steps","rank_math_description":"Find out how to create a WordPress theme to make your site truly unique: 1. Create the Template Files 2. Set Up the CSS Stylesheet and more.","rank_math_focus_keyword":"create WordPress theme","footnotes":""},"categories":[1],"tags":[],"class_list":["post-6015","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-create-a-wordpress-theme","default":0},{"locale":"pt-BR","link":"https:\/\/www.hostinger.com\/br\/tutoriais\/wordpress-como-criar-um-tema-responsivo-usando-html5","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/creer-un-theme-wordpress","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/crear-un-tema-de-wordpress-con-codigo","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/cara-membuat-tema-wordpress","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/create-wordpress-theme-html5","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/create-wordpress-theme-html5","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/create-wordpress-theme-html5","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/crear-un-tema-de-wordpress-con-codigo","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/crear-un-tema-de-wordpress-con-codigo","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/crear-un-tema-de-wordpress-con-codigo","default":0},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/pt\/tutoriais\/wordpress-como-criar-um-tema-responsivo-usando-html5","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/create-wordpress-theme-html5","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-create-a-wordpress-theme","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-create-a-wordpress-theme","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-create-a-wordpress-theme","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/posts\/6015","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/users\/72"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/comments?post=6015"}],"version-history":[{"count":89,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/posts\/6015\/revisions"}],"predecessor-version":[{"id":121056,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/posts\/6015\/revisions\/121056"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/media?parent=6015"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/categories?post=6015"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/tags?post=6015"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}