WordPress Themes

How to Code a WordPress Theme

wordpress-codeMost of us prefer our own style of coding which can assist in compressing huge and complex functions into a single code. We always like to avoid whitespace which can really takes up a huge amount of space. Now if you want to or going to develop codings for other people or trying to sell, then it is important that you should make the coding understandable.  Sometimes you may feel that the coding is quite clear enough, however, you ought to remember that there are certain standards (universal) which can assist people in creating codes with the same style.

Seriously, most of the theme marketplaces and the download centers would require one to do coding in a standard format. Now there are four major kinds of markup and programming languages which are quite necessary to create WordPress themes such as CSS, HTML, PHP and JavaScript.

So let’s check up these programming and markup languages.

 HTML Standard

In this, there are quite simple and easy rules for writing and developing compliant-standard HTML coding. In addition, you need to validate the coding with the W3C and you have to be careful with regard to the self closing items. You need to ensure that these items have to end with a slash, greater than sign, or space. Also when you are typing the values of the attribute, make sure that they are in lowercase.

It is important that you wrap the given values of the attribute in quotes. Both double and single quotes are acceptable. Even the indentation that you use must be readable and logical. It should not be an exception to have the HTML coding mixed with PHP codes.

CSS Standards

Here the list is quite long and again you do need to remember that the rules are easy for the CSS coding. It is important that the properties need to be indented with various tabs. In addition, you can group the given selectors but ensure that all the selectors have their own line for reading. Plus you have to name the entire given id selectors and class with lowercase alphabets and make sure to separate the words with hyphens.

The values and properties have to be in lowercase and that too except for vendor specific properties and even font names. You need to order the properties which have to be box model, positioning, display, typography, colors, etc. It is important that you order the vendor prefixes from the longest to the shortest. And make sure to keep the media queries to the below (bottom) of the given stylesheet.

JavaScript

javascriptNowadays, it is a common sight to see JavaScript being important for most of the WordPress themes. Of course, you need to have certain rules and standardization for it too. Braces should never be closed or opened within the exact line. Try to use single quotes over double quotes and that too unless there are strings which has the single quotes.

As a developer, you have the authority and the freedom to use whitespaces as much as you want in the coding. But try to avoid using the whitespaces on the blank lines. And one should not forget that the whitespaces are used for readability and never for fun.

You could name the variables and functions using the camelCase functions and not the ones with underscores. And the constructors have to be in the TitleCase. Even you have the option to declare various variables into a single line and in case if you are trying to assign these values, you need to separate the lines.

PHP Standards

This is the most complex part and there are quite a lot of rules that one needs to consider. Various aspects like double and single quotes, naming conventions, regular expressions, whitespace requirements, Yoda Conditions, etc need to be  defined. Even you have to take into account the special and easy to use SQL and formatting database and queries.

In case if you are not aware of what they consist of then the best option that you have to be tread a bit light. Now there are two interesting resources that you need to learn. The first one is WordPress PHP page (standard) at the Make WordPress.

The second one is properly commenting the codes. For this you need to allow other developers to know how you created the theme and ensure that the theme or coding is readable and clear. The opt practice that you have for PHP is using the PHPDoc, which is the documentation method of phpDocumentor. This is a commonly used between the various WordPress developers and is quite commonly recommended in the documentation of the PHP.

Frankly, it is important to be quite clear with regard to your coding and try to at least provide some tiny information while commenting whenever you feel necessary.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.