WordPress Tip: Be Careful with your Element Naming!

Just a minor tip to avoid your themes breaking...

  1. CM30

    CM30 Regular Member

    Joined:
    Jul 1, 2012
    Messages:
    901
    Likes Received:
    500
    CM30 submitted a new resource:

    WordPress Tip: Be Careful with your Element Naming! - Just a minor tip to avoid your themes breaking...

    Read more about this resource...
     
  2. Brandon

    Brandon Regular Member

    Joined:
    Jun 1, 2009
    Messages:
    6,602
    Likes Received:
    1,706
    Location:
    Topeka, Kansas
    First Name:
    Brandon
    Could you give examples of the wrong and right way to name classes?
     
  3. thebrad

    thebrad Regular Member

    Joined:
    Jun 29, 2013
    Messages:
    172
    Likes Received:
    18
    Location:
    Liverpool
    As brandon said can you give examples and can you please give us possibly a image to see what it would look like as soon as you do it? like the wordpress blog?
     
    Brandon likes this.
  4. CM30

    CM30 Regular Member

    Joined:
    Jul 1, 2012
    Messages:
    901
    Likes Received:
    500
    Well, if you need some examples, here are some:

    Don'ts:

    Don't give any HTML element a class called the following:
    • Home
    • Category
    • Blog
    • Single
    • Archive
    Do:

    Call your elements something slightly different, like:
    • Hub
    • Start
    • Journal
    etc. Or the ones I say not to use, plus a number or letter on the end of it. This is because a WordPress blog's body class will usually be set to something like:

    single single-post postid-[id number here]

    Or:

    archive category category-[name]

    So anything with 'category', 'archive', 'blog', etc as the class name will be overwritten on that respective page. This is very bad if you put something like:

    Code:
    .category {
    margin-left: 50%;
    width: 500px;
    color: red;
    }
    Since it'd end up making the entire page positioned 50% from the left of the screen, 500px wide and with all your text is red, regardless of your actual CSS for each element.
     
    Brandon likes this.
  5. thebrad

    thebrad Regular Member

    Joined:
    Jun 29, 2013
    Messages:
    172
    Likes Received:
    18
    Location:
    Liverpool
    Thankyou for this has helped alot i like the names you used aswell if you don't mine if i do create a blog i may think about using them.
     

Share This Page