• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Keeping Your WordPress Coding Clean and Neat

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Keeping Your WordPress Coding Clean and Neat

This topic is: not a support question

Tagged: clean code, coding, development, structure

  • This topic has 2 replies, 2 voices, and was last updated 9 years, 7 months ago by Jon Weiss.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • November 14, 2012 at 9:41 pm #169
    Jon Weiss
    Member

    Below are some snippets from a pretty neat article on Smashing Magazine about WordPress coding. I'd suggest checking out the article and learning a little more about the importance of tidy coding and how it can help you with both design and development of web sites.
    WHY CODE FORMATTING MATTERS
    Even if you’re working on a pet project, the format of your code says a lot. And if you’re in a multi-developer environment, it speaks volumes. Code that is well formatted and well thought out shows quality (even if it isn’t good), while chaos begets sloppy programming (even if it is genius).

    Here are but a few reasons to pay attention to the format of your code:

    Well-formed code is easier to maintain. You might know what’s going on today, but what about a year from now? Taking the time to give structure to your work will save you eons of time later on (… well, maybe not eons).
    Other developers do not share your brain, so they won’t understand your chaotic code, or they would need a long time to untangle it. Ensuring as little friction in communication as possible is in the project’s best interest, and this can be facilitated by standards-compliant formatting.
    Slightly less importantly, someone who is learning to program should be able to visit a website and learn something by looking at the source code. Standards usually have an inherent logic, so an onlooker would be able to figure out what’s going on. Adhering to standards could help a lot of budding developers learn programming the right way from day one.
    In many cases, good formatting helps maintainability. Many standards require you to space out if statements and other blocks of code. Not crowding the code together will make an “Error on line 267” message much easier to fix.

    PHP IN WORDPRESS
    Line breaks

    WordPress’ documentation says nothing in particular about line breaks, but adding a line break after most statements is common practice. Variable definitions, items and so on should be on separate lines.

    Indentation

    Indent code to show a logical structure. The goal here is readability, so any indentation that makes the code more readable is a good practice. Use tabs at the beginning of lines, and use spaces for mid-line indentation.

    Space usage

    Remove all trailing spaces from line endings. Empty lines with tabbed or non-breaking spaces is also common — remove these as well. But use spaces to make your code readable, most commonly within parentheses. Insert a break after an opening brace and before a closing brace, except when typecasting.
    FORMATTING CSS
    Consistent styling is just as important in CSS as in PHP and HTML. When a user wants to change a small detail in your theme, they will inevitably end up in a CSS file. Thus, the CSS could be the most visible code that you write. The “CSS Standards” document is a “rough draft.” Most of what’s there is probably there to stay, but as stated on the page itself, it is all subject to change.

    Follow the draft closely. If something changes, you’ll still be up to speed on most of the guidelines; and if your existing CSS code doesn’t adhere to it 100%, the reason will be understandable.

    --- View the full article here.


    View My Site – Two W Media.com | I’m a Recommended StudioPress Customizer

    November 15, 2012 at 5:03 pm #237
    Gary Jones
    Member

    As much as an I'm an advocate for following the coding standards, they do leave some holes within common examples of code, which means that inconsistency is introduced as different coders fill those holes with their own preferences. Multi-line function call arguments is an obvious one. It also doesn't cover items in PHP that are introduced in a version of PHP later than the required minimum, which again leaves developers who make the minimum requirement of their code to be 5.3 or later end up with inconsistent coding.

    My advice, would be to have PSR-2 as the common coding standard, except for where the WordPress Coding Standards explicitly define how the code should be formatted. A lot of packages and libraries outside of WordPress are tending towards PSR-0, PSR-1 and some to PSR-2, so for the sake of having those holes filled with someing, it makes sense to use a common modern standard from outside of WordPress.


    WordPress Engineer, and key contributor the Genesis Framework | @GaryJ

    November 16, 2012 at 1:28 pm #347
    Jon Weiss
    Member

    I agree Gary. Although there are definitely some things mentioned in the article that I'd say to follow, this was more intended for some of the newer coders / people looking for general tips. But I'd definitely recommend following the PSR-2 Standards as well.


    View My Site – Two W Media.com | I’m a Recommended StudioPress Customizer

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2022 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble