{"id":322,"date":"2012-01-09T01:08:53","date_gmt":"2012-01-08T16:08:53","guid":{"rendered":"http:\/\/www.santoshkori.com\/blog\/?p=322"},"modified":"2012-08-23T17:30:34","modified_gmt":"2012-08-23T08:30:34","slug":"how-to-create-a-wordpress-theme-from-scratch","status":"publish","type":"post","link":"https:\/\/www.santoshkori.com\/blog\/how-to-create-a-wordpress-theme-from-scratch\/","title":{"rendered":"How to Create a WordPress Theme from Scratch"},"content":{"rendered":"<p>Following on from the recent article on \u201cPSD to HTML\u201d, this tutorial  will look at taking a HTML\/CSS template and turning it into a  functioning WordPress theme. There is so much you can do when creating  your own theme we couldn\u2019t nearly cover it all. So, we\u2019re going to look  at how themes are structured, creation of the core files and splitting  up that index.html file.<!--more--><\/p>\n<h2>Overview \u2013 The Structure Of A WordPress Theme<\/h2>\n<p>The structure of a WordPress theme is fairly simple, I like to start  with the CSS    file. It details everything about the theme for  WordPress to use. You then have    <code>index.php<\/code> \u2013 it\u2019s simply the template file you\u2019re using with the PHP template    tags included. Included with that is <code>header.php<\/code> &amp; <code>footer.php<\/code>,     files that are used across the whole site. Now most themes don\u2019t use  just four files    and that\u2019s because WordPress allows you to use  template files to layout different    content. There are the defined  layout files, such as <code>archives.php<\/code> and    <code>single.php<\/code>. However you can also create your own, say, if you wanted    to make a page that had a totally different layout to the default.<\/p>\n<p>Because this is such a large topic we\u2019re splitting it into a two  part series \u2013 this    part making a simple but functioning theme from a  standard HTML &amp; CSS template,    and the second part will look at  adding more of the advanced features.<\/p>\n<p>I will be working on turning the great template \u201cTypography Paramount\u201d by <a href=\"http:\/\/www.sixshootermedia.com\/\" target=\"_blank\" rel=\"noopener\"> Six Shooter Media<\/a> into a simple WordPress theme.<\/p>\n<h2>Step 1 &#8211; style.css<\/h2>\n<p>The style sheet is the defining file of the theme for WordPress.  There are a few    simple things you need to do. The first is renaming  the main (if you have more that    one) file to <code>style.css<\/code>, next you need to add a bit of commenting to    the file.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\/*\r\nTheme Name: Typography Paramount\r\nTheme URI: http:\/\/www.sixshootermedia.com\/\r\nDescription: An image-less template focusing on Typography.\r\nAuthor: Sam Parkinson\r\nAuthor URI: http:\/\/xseria.com\r\nVersion: 1.0\r\n.\r\nGeneral comments\/License Statement if any.\r\n.\r\n*\/\r\n\r\n<\/pre>\n<p>The code above is all contained in a comment, so it won\u2019t affect the  style definitions.    Now I filled it out with a few details, these  will be used by WordPress to display    the details of the theme to  admins. Make sure you add it to the top of the file    with no  white-spaces before it.<\/p>\n<p>I\u2019ve gone and renamed the style sheet file from the template, it was called <code>1.css<\/code>.    I have also made a new folder called <code>typography-paramount<\/code> which will    be what I upload to the WordPress theme folder. Put the  style sheet in this folder,    but not under another directory otherwise  it cannot be seen by WordPress.<\/p>\n<p><a href=\"https:\/\/www.santoshkori.com\/blog\/wp-content\/uploads\/2012\/01\/photoshop-to-wordpresstheme-from-scratch.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-323\" title=\"photoshop-to-wordpresstheme-from-scratch\" src=\"https:\/\/www.santoshkori.com\/blog\/wp-content\/uploads\/2012\/01\/photoshop-to-wordpresstheme-from-scratch.jpg\" alt=\"\" width=\"600\" height=\"497\" srcset=\"https:\/\/www.santoshkori.com\/blog\/wp-content\/uploads\/2012\/01\/photoshop-to-wordpresstheme-from-scratch.jpg 600w, https:\/\/www.santoshkori.com\/blog\/wp-content\/uploads\/2012\/01\/photoshop-to-wordpresstheme-from-scratch-300x248.jpg 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<h2>Step 2 &#8211; The Header and Footer<\/h2>\n<p>In this step, we\u2019re going to create the two files: <code>header.php<\/code> and <code>footer.php<\/code>.    Although they are optional both are used in most themes, they\u2019re not exactly hard    to use either.<\/p>\n<h4>header.php<\/h4>\n<p>Starting with the header, create a new file in the theme folder called <code>header.php<\/code>,    then open up <code>index.html<\/code> from the template and copy the following from    it. This will become  the header and will be displayed on every page of the site,    bear that  in mind when making other templates.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html PUBLIC &quot;-\/\/W3C\/\/DTD XHTML 1.1\/\/EN&quot; &quot;http:\/\/www.w3.org\/TR\/xhtml11\/DTD\/xhtml11.dtd&quot;&gt;\r\n&lt;html xmlns=&quot;http:\/\/www.w3.org\/1999\/xhtml&quot; xml:lang=&quot;en&quot;&gt;\r\n&lt;head&gt;\r\n&lt;title&gt;-&lt;\/title&gt;\r\n&lt;meta http-equiv=&quot;content-type&quot; content=&quot;text\/html; charset=utf-8&quot; \/&gt;\r\n&lt;link rel=&quot;stylesheet&quot; href=&quot;css\/1.css&quot; type=&quot;text\/css&quot; media=&quot;screen,projection&quot; \/&gt;\r\n\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n\r\n&lt;div id=&quot;wrapper&quot;&gt;\r\n\r\n\t&lt;div id=&quot;header&quot;&gt;\r\n\r\n\t&lt;p class=&quot;description&quot;&gt;\r\n\r\n\tAn imageless template focusing on Typography.\r\n\r\n\t&lt;\/p&gt;\r\n\r\n\t&lt;h1&gt;&lt;a href=&quot;#&quot;&gt;Typography Paramount&lt;\/a&gt;&lt;\/h1&gt;\r\n\r\n\t&lt;ul id=&quot;nav&quot;&gt;\r\n\r\n\t&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Link Here&lt;\/a&gt;&lt;\/li&gt;\r\n\r\n\t&lt;li&gt;&lt;a href=&quot;#&quot; class=&quot;active&quot;&gt;Link Here&lt;\/a&gt;&lt;\/li&gt;\r\n\r\n\t&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Link Here&lt;\/a&gt;&lt;\/li&gt;\r\n\r\n\t&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Link Here&lt;\/a&gt;&lt;\/li&gt;\r\n\r\n\t&lt;li&gt;&lt;a href=&quot;#&quot;&gt;Link Here&lt;\/a&gt;&lt;\/li&gt;\r\n\r\n\t&lt;\/ul&gt;\r\n\r\n\t&lt;\/div&gt;\r\n\r\n<\/pre>\n<p>We\u2019re now going to add the WordPress template tags to header.php, these tell WordPress where to inject the various content into the theme. Also remember to change that link to the stylesheet.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html PUBLIC &quot;-\/\/W3C\/\/DTD XHTML 1.1\/\/EN&quot; &quot;http:\/\/www.w3.org\/TR\/xhtml11\/DTD\/xhtml11.dtd&quot;&gt;\r\n&lt;html xmlns=&quot;http:\/\/www.w3.org\/1999\/xhtml&quot; &lt;?php language_attributes() ?&gt;&gt;\r\n&lt;head profile=&quot;http:\/\/gmpg.org\/xfn\/11&quot;&gt;\r\n&lt;title&gt;&lt;?php bloginfo('name'); ?&gt; &lt;?php wp_title(); ?&gt;&lt;\/title&gt;\r\n&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;&lt;?php bloginfo('html_type'); ?&gt;; charset=&lt;?php bloginfo('charset'); ?&gt;&quot; \/&gt;\r\n&lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?php bloginfo('stylesheet_url'); ?&gt;&quot; type=&quot;text\/css&quot; media=&quot;screen,projection&quot; \/&gt;\r\n\r\n&lt;?php wp_head(); ?&gt;\r\n\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n\r\n&lt;div id=&quot;wrapper&quot;&gt;\r\n\r\n\t&lt;div id=&quot;header&quot;&gt;\r\n\r\n\t&lt;p class=&quot;description&quot;&gt;&lt;?php bloginfo('description'); ?&gt;&lt;\/p&gt;\r\n\r\n\t&lt;h1&gt;&lt;a href=&quot;&lt;?php echo get_option('home'); ?&gt;\/&quot;&gt;&lt;?php bloginfo('name'); ?&gt;&lt;\/a&gt;&lt;\/h1&gt;\r\n\r\n\t&lt;ul id=&quot;nav&quot;&gt;\r\n\t&lt;?php wp_list_pages('sort_column=menu_order&amp;title_li='); ?&gt;\r\n\t&lt;\/ul&gt;\r\n\r\n\t&lt;\/div&gt;\r\n\r\n<\/pre>\n<p>There\u2019s quite a lot that\u2019s been added but it\u2019s all fairly simple when  you look through    it. All the tags above are well documented in the <a href=\"http:\/\/codex.wordpress.org\/\" target=\"_blank\" rel=\"noopener\"> WordPress Codex<\/a>. I\u2019m just going to go through what each of the functions    do.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Following on from the recent article on \u201cPSD to HTML\u201d, this tutorial will look at taking a HTML\/CSS template and turning it into a functioning WordPress theme. There is so much you can do when creating your own theme we couldn\u2019t nearly cover it all. So, we\u2019re going to look at how themes are structured, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[168,170,169,725],"class_list":["post-322","post","type-post","status-publish","format-standard","hentry","category-web-development","tag-create-a-wordpress-theme-from-scratch","tag-how-to-create-a-wordpress-theme","tag-how-to-create-a-wordpress-theme-from-scratch","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/322","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/comments?post=322"}],"version-history":[{"count":10,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/322\/revisions"}],"predecessor-version":[{"id":698,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/322\/revisions\/698"}],"wp:attachment":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/media?parent=322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/categories?post=322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/tags?post=322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}