How to Code a Wordpress Theme

Coding a Wordpress theme

Creating the Perfect WordPress Theme: How to Code Well Previously in this part of the session, we went through several WordPress APIs to find out more about, spoke about the importance of making a topic translateable (or even better, publishing it already in other languages ), and grasped the concepts of subject license and using licenced product with the topics. We' ll concentrate on the code in this article: We will see how to code with WordPress encoding defaults, how to correctly annotate our code and how to test and verify the topic. Yes, I know you have your own favorite programming style: you like to zip a big feature with a line of code, you don't like white space that much - Ah, I used to be just like that.

However, if you want to create for others and want to virtually resell your code, you need to make your code work. While you may think that your code is "clear enough", there are general purpose encoding defaults that help everyone encode with the same stile, and all serious theme markets and downloading centres (from WordPress.org to ThemeForest) demand that you encode with defaults.

Four major language programs and markups are required for developing WordPress themes: HTML, CSS, JavaScript and of course PHP. Relatively easy to follow HTML code authoring guidelines exist: Use W3C to verify your code. The PHP code merged within the HTML should not be an exception. However, it should not be an HTML code. For more information, see the WordPress HTML Standard page under Make WordPress.

There is a longer version, but there are also simple guidelines for correct encoding: Annotate your style sheet code as you annotate in PHP. For a more detailled description see the page WordPress CSS Standard under Make WordPress. As JavaScript is becoming more and more important for many WordPress topics these days, we need the necessary standard and rules:

You can use spaces as you like in your code - but don't use spaces in empty rows. Remember that you use spaces for better legibility - not for pleasure. The use of parentheses and spaces is the code. Take a look at the example to be sure. For more information, see the WordPress JavaScript Standards page under Make WordPress, page this page to be bookmarked and used.

The PHP standards: However, there are two great ressources you can use to study it: For other designers to comprehend how you created your design, you need to make your design code clear and legible - and that calls for a comment on your code. For PHP, the best approach is to use PHPDoc, the document writing language of PhpDocumentor.

It is often used by WordPress developpers and on the PHP documentation standards page under Make WordPress it is suggested. Provides a neat way to document your PHP code. Concerning styles, the WordPress Standards page under Make WordPress suggests that you do it like PHPDoc, along with a few other proposals.

Concerning your HTML and JavaScript code, it seems that there is no way to annotate your code that is either encouraged or necessary, but that doesn't mean you don't have to do anything: try to be as clear as possible with your code and make small pieces of information available by annotating wherever you feel necessary.

This theme can work as a proper website in your mind, but hopefully there will be hundred (maybe thousands) of different individuals who will use your theme and be sure that they will try to create sites that you can't possibly think of. There are also demands on theme market places and theme lists so that you can compile your theme.

Therefore, you need to test your design and verify your code. First thing you need to do is verify your code with the W3C verification team. Once you have performed the following two steps, just review the demonstration pages with these two utilities to make sure there are no bugs or alerts.

The Developer is a free plug-in created by Automatic that allows WordPress programmers to create WordPress files. Some of them simplify your design processes considerably (e.g. User Switching and Theme Test Drive), while others help you with debugging your theme (e.g. Log Deprecated Notices and Theme Check). Those I find most useful are Theme Checks, Theme Test Drives and Bug Bar, but all 16 plug-ins offer great functionality.

to test the whole thing out of your theme. Can' t just code the design and say it's done - you have to test it with some contents. While you can make your own contents, you should consider using some "test data" to test them:

You can use the WordPress example files. These example dates contain some of the most commonly used contents and help you identify the flaws in your topic compared to contents you have forgotten. You can use more extensive test datas. io is a small website with a frightening compilation of WordPress examples. This is the most comprehensive test set I've ever seen of 10 level deeper menus and Amazon Store embedding.

I' ve never tried a design with this example but if you manage to make your design work with this information, you probably won't have to be concerned that your design won't look boring in any scenarios. But the only drawback of these two testing methods is that you can't test your contents with shortcuts or the kind of custom contents you had in mind when you developed the topic.

My suggestion is that you test the topic with at least WordPress example files and then build your own custom part. Finally, you need sound contents when you are creating the demonstration website for your topic. We went through the process of correct encoding and annotation with some standardization, then we saw how to invalidate our code and test our subject.

Auch interessant

Mehr zum Thema