{"id":4015,"date":"2020-07-03T21:05:48","date_gmt":"2020-07-04T04:05:48","guid":{"rendered":"http:\/\/www.eaf.net\/mvp\/?p=4015"},"modified":"2020-07-03T21:05:48","modified_gmt":"2020-07-04T04:05:48","slug":"create-a-custom-wordpress-page-template-for-html-content","status":"publish","type":"post","link":"https:\/\/www.eaf.net\/mvp\/2020\/create-a-custom-wordpress-page-template-for-html-content\/","title":{"rendered":"Create A Custom WordPress Page Template for HTML Content"},"content":{"rendered":"<p><strong>Problem:<\/strong> You have an HTML-only web page, carefully designed, that you want to bring as-is into WordPress without investing hours on redesign.<\/p>\n<p><strong>Compounding problem:<\/strong> This page uses three includes as well as a responsive layout and stylesheets that are entirely different from anything offered by the WordPress you are using.<\/p>\n<p><strong>Solution:<\/strong> Create a special single-use custom WordPress page template.<\/p>\n<p><strong>Good news:<\/strong> I&#8217;m about to tell you how to do this.<\/p>\n<p><strong>Additional good news:<\/strong> The concept below can be modified into additional WordPress page templates for bringing in other HTML content into WordPress-powered sites. <!--more--><\/p>\n<p><strong>Bad news:<\/strong> I don&#8217;t know of any (related to this particular subject). Wait. There&#8217;s just a bit of bad news: I have some background to tell you about before showing you the WordPress page template. If you&#8217;re not interested, you don&#8217;t need me to tell you to just scroll past the next section.<\/p>\n<h2>Background<\/h2>\n<p>My oldest website just turned 25. Yes, twenty-five years old. That&#8217;s almost prehistoric on the Web. Do you realize how many websites existed in mid-1995? Not many; as in, <a href=\"https:\/\/royal.pingdom.com\/internet-1995\/\">23,500<\/a>.<\/p>\n<p>That site is entirely hand-coded in static HTML. I&#8217;m wanting to migrate it to WordPress. At the rate I&#8217;m going, I&#8217;ll be dead a long time before I get the project done. We&#8217;re talking hundreds of pages!<\/p>\n<p>I have WordPress set up and running on the site. I haven&#8217;t converted any old content, but <a href=\"https:\/\/www.anabaptists.org\/essays\/\">recent content additions<\/a> I&#8217;ve done in WordPress.<\/p>\n<p>Actually, several days ago I also brought my old home page into WordPress. I created a php-free template to generate an exact replica of my original hand-coded static-html home page. The screen capture here shows you what the page looked like before I brought it into WordPress&#8230;and what it looks like now that it is generated by WordPress.<\/p>\n<p><a href=\"https:\/\/www.anabaptists.org\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.eaf.net\/mvp\/wp-content\/anabaptists-home-page.jpg\" alt=\"Anabaptists Home Page\" width=\"940\" height=\"435\" class=\"aligncenter size-full wp-image-4023\" style=\"border-top:10px darkgreen solid; border-bottom:10px darkgreen solid\" srcset=\"https:\/\/www.eaf.net\/mvp\/wp-content\/anabaptists-home-page.jpg 940w, https:\/\/www.eaf.net\/mvp\/wp-content\/anabaptists-home-page-400x185.jpg 400w, https:\/\/www.eaf.net\/mvp\/wp-content\/anabaptists-home-page-150x69.jpg 150w, https:\/\/www.eaf.net\/mvp\/wp-content\/anabaptists-home-page-768x355.jpg 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/a><\/p>\n<p><strong>Exciting News:<\/strong> I&#8217;m about to tell you how I accomplished that. \ud83d\ude00 \ud83d\ude2f \ud83d\ude33<\/p>\n<h2>Mark Roth&#8217;s One-Use Theme-Agnostic WordPress Page Template<\/h2>\n<p>As I recall, I used Notepad to create this template. I used <em>page-html-home.txt<\/em> as the name for my new document. (There&#8217;s WordPress-logical reason for the name, which I&#8217;ll reveal in a bit.)<\/p>\n<p>My custom template requires only one line of PHP code. That&#8217;s the line that gives the template its name. It goes at the very top. Here it is:<\/p>\n<pre style=\"background-color:lightyellow; margin-top:-1em\">&lt;?php Template Name: HTML Home ?&gt;<\/pre>\n<p>Actually, I added some comments to my template as well, but they aren&#8217;t required. Curious? OK, Here you are:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.eaf.net\/mvp\/wp-content\/wordpress-template-editing-screen.jpg\" alt=\"WordPress page template editing screen\" width=\"1080\" height=\"310\" class=\"aligncenter size-full wp-image-4024\" style=\"border-top:10px darkgreen solid; border-bottom:10px darkgreen solid\" srcset=\"https:\/\/www.eaf.net\/mvp\/wp-content\/wordpress-template-editing-screen.jpg 1080w, https:\/\/www.eaf.net\/mvp\/wp-content\/wordpress-template-editing-screen-400x115.jpg 400w, https:\/\/www.eaf.net\/mvp\/wp-content\/wordpress-template-editing-screen-1024x294.jpg 1024w, https:\/\/www.eaf.net\/mvp\/wp-content\/wordpress-template-editing-screen-150x43.jpg 150w, https:\/\/www.eaf.net\/mvp\/wp-content\/wordpress-template-editing-screen-768x220.jpg 768w\" sizes=\"auto, (max-width: 1080px) 100vw, 1080px\" \/><\/p>\n<p>Below that PHP code I simply pasted in all the HTML code for the original hand-coded page. Yes, I mean <em><strong>all the code<\/strong><\/em>, beginning with the very first line and ending with the very last one. For me, that&#8217;s these two:<\/p>\n<pre style=\"background-color:lightyellow; margin-top:-1em\">&lt;!doctype html&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>After closing the document, I <strong>renamed<\/strong> it <em>page-html-home.php<\/em> so WordPress could use it. Then I <strong>uploaded<\/strong> it to the proper WordPress directory on my site&#8217;s server. (I use <a href=\"https:\/\/wordpress.org\/themes\/generatepress\/\">GeneratePress<\/a> and a child theme, but this should work with any WordPress theme.)<\/p>\n<h2>Some Modifications to Make to the Custom Page Template<\/h2>\n<p>If you are still with me so far in the development of your own template, log into your WordPress admin site and <strong>edit<\/strong> your new page template.<\/p>\n<p>One type of change I had to make was to update some of the script, stylesheet, and link <strong>paths<\/strong>. For example, since my home page uses CSS stylesheets that are not part of WordPress, I had to make sure that I used the correct paths in my special template.<\/p>\n<p>Since my home page also uses three HTML <strong>includes<\/strong>, I had to change those since WordPress wouldn&#8217;t process those (of course). If you want a truly PHP-free solution, replace the includes with the full text of the files they insert. Otherwise, add some PHP code to do the including for you.<\/p>\n<p>Instead of HTML code like this:<\/p>\n<pre style=\"background-color:lightyellow; margin-top:-1em\">&lt;!--#include virtual=&quot;\/chunks\/footer.html&quot; --&gt;<\/pre>\n<p>Use PHP code like this:<\/p>\n<pre style=\"background-color:lightyellow; margin-top:-1em\">&lt;?php include &quot;.\/chunks\/footer.html&quot; ?&gt;<\/pre>\n<p>Save your modified template and take it for a test drive.<\/p>\n<h2>How to Use Your New Custom Page Template<\/h2>\n<p>Create a new page. I titled mine <em>HTML Home<\/em>. Notice the resemblance to the name of the template and its file.<\/p>\n<p>As you can see in this image, I added no content to the page. That&#8217;s because all the content is in the template I created just for this purpose.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.eaf.net\/mvp\/wp-content\/wordpress-page-writing-screen.jpg\" alt=\"WordPress page writing screen\" width=\"960\" height=\"465\" class=\"aligncenter size-full wp-image-4025\" style=\"border-top:10px darkgreen solid; border-bottom:10px darkgreen solid\" srcset=\"https:\/\/www.eaf.net\/mvp\/wp-content\/wordpress-page-writing-screen.jpg 960w, https:\/\/www.eaf.net\/mvp\/wp-content\/wordpress-page-writing-screen-400x194.jpg 400w, https:\/\/www.eaf.net\/mvp\/wp-content\/wordpress-page-writing-screen-150x73.jpg 150w, https:\/\/www.eaf.net\/mvp\/wp-content\/wordpress-page-writing-screen-768x372.jpg 768w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/p>\n<p>Also notice in the image above that I didn&#8217;t assign my custom template to this page. I could have. But I don&#8217;t really need to. That&#8217;s because WordPress does it automatically since I used those matching names I mentioned earlier. Let me see if can explain&#8230;<\/p>\n<p>When WordPress serves up a page&#8230;<\/p>\n<ol>\n<li>It first checks to see if a template was assigned to it. If there is, it finds and uses it.<\/li>\n<li>If the page does not have a template assigned to it, WordPress then checks to see if there&#8217;s a page template that matches the page&#8217;s slug. WordPress finds <em>page-html-home.php<\/em> and serves up this page based on that template. (For more about this kind of stuff, check out what WordPress has to say about its <a href=\"https:\/\/developer.wordpress.org\/themes\/basics\/template-hierarchy\/\" title=\"template hierarchy\">template hierarchy<\/a>).<\/li>\n<\/ol>\n<p>So, save your new page as a draft and then preview it.<\/p>\n<h2>Don&#8217;t Forget This!<\/h2>\n<p>Since my custom template was supposed to serve up a replacement home page, I had to change my site&#8217;s WordPress <em>Reading Settings<\/em> to use my <em>HTML Home<\/em> page as the home page.<\/p>\n<p>Then I had to FTP into my site&#8217;s root directory and <strong>delete<\/strong> the original <em>index.html<\/em> file there.<\/p>\n<p>And that&#8217;s it.<\/p>\n<p>I hope you found this helpful. If there&#8217;s anything I need to clarify or correct, please let me know.<\/p>\n<p>PS: I figure to use this basic approach to create another page template to use for hundreds of <a href=\"https:\/\/www.anabaptists.org\/clp\/youth\/\">&#8220;Applications of Truth&#8221; meditations<\/a> I want to add next to my <em>Anabaptists<\/em> site.<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>A fast, easy, simple way to effectively bring old HTML pages into WordPress<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"Create A Custom WordPress Page Template for HTML Content","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[13],"tags":[909,716],"class_list":["post-4015","post","type-post","status-publish","format-standard","hentry","category-tech-stuff","tag-tips","tag-wordpress"],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/prJUJ-12L","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/posts\/4015","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/comments?post=4015"}],"version-history":[{"count":0,"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/posts\/4015\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/media?parent=4015"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/categories?post=4015"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/tags?post=4015"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}