Skip to content

Styling Your Theme – Time to Look Fabulous 💅

Making Your Theme Shine: It's All About the Style

Alright, we’ve got the bones of the theme in place, but right now it’s like a blank white canvas. And let’s be honest – no one ever looked at a blank website and thought, “Wow, this is beautiful.” So, we need to start adding some color and structure with CSS to make our theme look awesome.

Step 1: Adding Basic CSS to style.css

Remember that lonely style.css file we created in the last chapter? It’s time to give it some love. Let’s add some basic styling to make the theme look a bit more professional.

Go ahead and open style.css in your theme folder. We’re going to start by adding a few basic styles:

css
/* Basic Theme Styles */

body {
  font-family: Arial, sans-serif;
  margin: 0;
  padding: 0;
  background-color: #f4f4f4;
}

h1 {
  color: #333;
  text-align: center;
  margin: 50px 0 20px;
}

p {
  color: #666;
  text-align: center;
  font-size: 18px;
}

a {
  color: #0073aa;
  text-decoration: none;
}

a:hover {
  color: #005177;
}

header,
footer {
  background-color: #333;
  color: white;
  padding: 10px 0;
  text-align: center;
}

What’s happening here?

  • We’re giving the body a simple, clean font (Arial) and setting a background color.
  • Our headings (h1) are centered and looking sharp with a nice dark grey color.
  • We’re styling the paragraph (p) text to be a bit lighter and centered.
  • Links (a) get the classic blue color and a hover effect that changes the shade.
  • We’ve added some basic styling to the header and footer to make them stand out.

Step 2: Enqueueing Styles and Scripts the WordPress Way

Hold on, cowboy! Before we get too far ahead, there’s a WordPress way of doing things. WordPress likes to keep things neat and tidy, and it has a special function for including CSS and JavaScript files.

In WordPress, we don't just throw our stylesheets into the HTML with <link>. Nope. We enqueue them. (Don’t worry, it’s not as scary as it sounds.)

Open functions.php (if you haven’t created it yet, make one now in your theme folder) and add the following code to enqueue your style.css:

php
<?php
function my_noob_theme_enqueue_styles() {
    wp_enqueue_style('my-noob-theme-style', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts', 'my_noob_theme_enqueue_styles');

What does this do?

  • wp_enqueue_style() – This tells WordPress, “Hey, here’s my CSS file! Please load it properly.”
  • get_stylesheet_uri() – This points WordPress to your style.css file.

Now WordPress knows exactly how to include your styles, the right way.

Step 3: Flexbox for Layout – Let’s Get Flexible 🧘‍♀️

Let’s make the layout of the page a bit more interesting by introducing Flexbox, the modern way to create flexible and responsive layouts.

Add some more CSS to your style.css:

css
/* Flexbox Layout for Main Content */

.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.content {
  background-color: white;
  padding: 20px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  border-radius: 10px;
  max-width: 800px;
  width: 100%;
  text-align: center;
}

What’s happening here?

  • We’re using Flexbox to center the .container both vertically and horizontally (because why not be fancy?).
  • The .content class is applied to the main content block, giving it a nice white background, some padding, a soft shadow, and rounded corners.

Step 4: Linking the Layout to Your Template

Now, let’s apply this new layout to your template. Go back to index.php and wrap the content in a .container and .content div:

php
<?php get_header(); ?>

<div class="container">
    <div class="content">
        <h1>Welcome to My Noob Theme!</h1>
        <p>This is your very first custom WordPress theme. Woohoo!</p>
    </div>
</div>

<?php get_footer(); ?>

Refresh your site, and boom – you’ve got a nice centered block of content with a clean, modern look. Flexbox makes this layout responsive too, so it will look great on mobile devices without any extra effort. High five! 🙌

Step 5: Adding a Responsive Navigation Menu 🍔

No website is complete without a navigation menu, right? Let’s add one to the header.

First, update header.php to include a basic menu:

php
<header>
    <h1><?php bloginfo('name'); ?></h1>
    <nav>
        <?php wp_nav_menu(array('theme_location' => 'primary')); ?>
    </nav>
</header>

Now we need to register the menu in functions.php:

php
<?php
function my_noob_theme_setup() {
    // Register the navigation menu
    register_nav_menus(array(
        'primary' => __('Primary Menu', 'my-noob-theme'),
    ));
}
add_action('after_setup_theme', 'my_noob_theme_setup');

This code registers a "Primary Menu" location for WordPress to display. Head over to your WordPress admin dashboard (Appearance > Menus) and create a new menu. Assign it to the "Primary Menu" location, and your links will show up.

Now add some basic styling to your style.css:

css
nav ul {
  list-style: none;
  padding: 0;
  display: flex;
  justify-content: center;
}

nav ul li {
  margin: 0 15px;
}

nav ul li a {
  color: white;
  font-size: 18px;
  text-transform: uppercase;
}

This will create a clean, horizontal navigation bar.

Step 6: Making it Responsive (a.k.a. "Mobile Ready") 📱

Finally, we want to make sure our theme looks good on all devices. Add some media queries to style.css to make your layout mobile-friendly:

css
/* Mobile Styles */
@media (max-width: 768px) {
  h1 {
    font-size: 24px;
  }

  p {
    font-size: 16px;
  }

  nav ul {
    flex-direction: column;
  }

  nav ul li {
    margin: 10px 0;
  }
}

These styles will ensure your theme adapts to smaller screens, with the navigation stacking vertically and the text resizing for readability.

Up Next: Adding Functionality with WordPress Loops 🌀

Now that our theme is looking sharp, it’s time to start making it functional. In the next chapter, we’ll dive into the Loop – the core of WordPress theme development that controls how posts and pages are displayed.

We’ll make your theme dynamic, so it doesn’t just show static content but actually pulls posts from WordPress!

Built by noobs, for noobs, with love 💻❤️