{"id":2104,"date":"2017-10-10T17:43:07","date_gmt":"2017-10-10T12:13:07","guid":{"rendered":"http:\/\/mandmwebsolutions.com\/blog\/?p=2104"},"modified":"2018-04-24T15:02:15","modified_gmt":"2018-04-24T09:32:15","slug":"wordpress-theme-development-best-practices","status":"publish","type":"post","link":"http:\/\/mandmwebsolutions.com\/blog\/wordpress-theme-development-best-practices\/","title":{"rendered":"8 Best Practices To Develop WordPress Theme From Scratch"},"content":{"rendered":"<p>In this article, we will talk about some of the best practices for WordPress theme development.<\/p>\n<p>Given below are the best practices for WordPress theme development:<\/p>\n<h2>1. WordPress coding standards<\/h2>\n<p>WordPress has well-established coding standards for PHP, HTML, and CSS. You need to code your WordPress themes using the following standards:<\/p>\n<ul class=\"innerlist\">\n<li>You should use well-structured, error-free PHP and valid HTML.<\/li>\n<li>Use clean, valid CSS.<\/li>\n<li>Follow design guidelines.<\/li>\n<\/ul>\n<h2>2. Theme Stylesheet<\/h2>\n<p>Some of the stylesheet guidelines you need to follow:<\/p>\n<ul class=\"innerlist\">\n<li>When authoring your CSS, you should follow CSS coding guidelines.<\/li>\n<li>Use valid CSS when possible.<\/li>\n<li>Minimize CSS hacks.<\/li>\n<li>Style all possible HTML elements: tables, captions, images, lists, block quotes, etc. by your theme, in post\/page content, and in comment content.<\/li>\n<li>You can add print-friendly styles.<\/li>\n<\/ul>\n<h2>3. Theme files<\/h2>\n<p>WordPress themes can include three to four languages: HTML, CSS, PHP, and JavaScript.<\/p>\n<p>You need to keep your resources organized. Some of the theme files organization guidelines you can follow:<\/p>\n<ul class=\"innerlist\">\n<li>Set up template files for header.php, footer.php, sidebar.php etc.<\/li>\n<li>Keep your main template files in the theme\u2019s root directory.<\/li>\n<li>You should give JavaScript, page templates, CSS, image, and language files\u00a0in their own directory.<\/li>\n<li>You should prefix page template <strong>page-about-template.php <\/strong>or nest inside <strong>page-templates<\/strong> folder<\/li>\n<\/ul>\n<h2>4. Template hierarchy<\/h2>\n<p><em>There is a hierarchy that determines the template WordPress platform will use for each. Templates are chosen and generated based on the Template hierarchy.<\/em><\/p>\n<p><em>You need to have a proper understanding of the hierarchy and familiarize yourself with it for theme development.<\/em><\/p>\n<h2>5. Theme localization and internationalization<\/h2>\n<p>The WordPress platform has been so widely adopted that the market for themes isn\u2019t limited to a single language.<\/p>\n<p><em>You should make your themes translation ready as WordPress makes it very easy to localize your theme.<\/em><\/p>\n<h2>6. Theme options<\/h2>\n<p>With WordPress theme option panel, you can change many options like Google Analytics ID, background color, header logo, codes etc.<\/p>\n<p>The wp_head, wp_footer and comment_form hooks are used by many plugins. You need to implement wp_head () in the head section of the header.php file, wp_footer() in footer.php file and do_action at the end of the comment form in comments.php file.<\/p>\n<h2>7. Template files<\/h2>\n<p>If you want to load another template other than header, sidebar, footer into a template, you can use get_template_part(). Now, it is easy for a theme to reuse sections of code.<\/p>\n<h2>8. Test your theme<\/h2>\n<p>You need to test your theme before releasing it to the public.<\/p>\n<p>If you\u2019re using the theme for yourself or a client, you should run it through a testing process given below:<\/p>\n<ul class=\"innerlist\">\n<li>You need to find and fix PHP and WordPress errors. Add define(\u2018WP_DEBUG\u2019, true); to your wp-config.php to enable debug settings and see deprecated function calls and other WordPress related errors.<\/li>\n<li>You can test theme with all your target browsers, for e.g. Chrome, Firefox, Opera, Safari etc.<\/li>\n<li>Check template files against Template File Checklist.<\/li>\n<li>Validate HTML and CSS.<\/li>\n<li>You should also check for JavaScript errors if you have used in your theme.<\/li>\n<\/ul>\n<p>These are the 8 best practices you can follow for your WordPress theme development.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Need to develop your own WordPress theme from scratch? This guide will show you how to build a custom theme from scratch with best practices.<\/p>\n","protected":false},"author":1,"featured_media":2205,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[36],"tags":[53,59,58,50,47,46,60,57,52,51,44,45,48,49,56,42,41,43,55,54],"class_list":["post-2104","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","tag-cheap-digital-marketing-agency-kolkata","tag-cheap-facebook-promotion-kolkata","tag-cheap-seo-services-kolkata","tag-digital-marketing-agencies-in-kolkata","tag-digital-marketing-agency-india","tag-digital-marketing-kolkata","tag-facebook-marketing-kolkata","tag-facebook-promotion-kolkata","tag-seo-company-in-kolkata","tag-seo-services-kolkata","tag-social-media-agency-kolkata","tag-social-media-kolkata","tag-social-media-marketing-company-in-kolkata","tag-social-media-marketing-kolkata","tag-social-media-marketing-services-in-kolkata","tag-top-digital-marketing-agencies-in-kolkata","tag-top-digital-marketing-companies-in-kolkata","tag-web-design-company-kolkata","tag-web-designer-kolkata","tag-web-development-company-kolkata"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"http:\/\/mandmwebsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/mandmwebsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mandmwebsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mandmwebsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/mandmwebsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=2104"}],"version-history":[{"count":8,"href":"http:\/\/mandmwebsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2104\/revisions"}],"predecessor-version":[{"id":2502,"href":"http:\/\/mandmwebsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2104\/revisions\/2502"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/mandmwebsolutions.com\/blog\/wp-json\/wp\/v2\/media\/2205"}],"wp:attachment":[{"href":"http:\/\/mandmwebsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=2104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mandmwebsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=2104"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mandmwebsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=2104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}