Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

How to Create a WordPress Theme and Not Die in the Attempt

Tiempo de lectura: 4 minutos


Hello, today we are going to learn how to create a WordPress theme using PHP + HTML + CSS + Javascript and we won’t die trying.

We are going to create a foundation upon which we can build different themes, and we’ll also use Bootstrap as a design library.

First, we need to have WordPress installed on our machine. In my case, I’m using Docker.

Now let’s start creating the theme. To do this, we’ll create the folder for our theme within wp-content/themes/. In my case, I’ll name it customtheme.

Now let’s add the different base files for our theme.

We create style.css with the following content:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/*
Theme Name: My Custom Theme
Description: A custom theme for my site.
Version: 1.0
Author: Your Name
*/
/* Global styles can go here */
body {
background-color: #f8f9fa;
color: #343a40;
}
.container {
background-color: #ffffff;
border: 1px solid #dee2e6;
border-radius: 5px;
padding: 20px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
}
h2 {
color: #007bff;
}
.text-muted {
font-size: 14px;
}
.btn-primary {
background-color: #007bff;
border-color: #007bff;
}
.btn-primary:hover {
background-color: #0056b3;
border-color: #0056b3;
}
/* Theme Name: My Custom Theme Description: A custom theme for my site. Version: 1.0 Author: Your Name */ /* Global styles can go here */ body { background-color: #f8f9fa; color: #343a40; } .container { background-color: #ffffff; border: 1px solid #dee2e6; border-radius: 5px; padding: 20px; box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1); } h2 { color: #007bff; } .text-muted { font-size: 14px; } .btn-primary { background-color: #007bff; border-color: #007bff; } .btn-primary:hover { background-color: #0056b3; border-color: #0056b3; }
/*
Theme Name: My Custom Theme
Description: A custom theme for my site.
Version: 1.0
Author: Your Name
*/

/* Global styles can go here */
body {
    background-color: #f8f9fa;
    color: #343a40;
}

.container {
    background-color: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 5px;
    padding: 20px;
    box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
}

h2 {
    color: #007bff;
}

.text-muted {
    font-size: 14px;
}

.btn-primary {
    background-color: #007bff;
    border-color: #007bff;
}

.btn-primary:hover {
    background-color: #0056b3;
    border-color: #0056b3;
}

Here we will add the different styles for our theme.

Now let’s create the index.php file.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php get_header(); ?>
<div class="container mt-5">
<div class="row">
<div class="col-md-8">
<?php
if (have_posts()) :
while (have_posts()) :
the_post();
?>
<article <?php post_class('mb-5'); ?>>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="text-muted"><?php the_date(); ?> by <?php the_author(); ?></p>
<?php the_excerpt(); ?>
<a href="<?php the_permalink(); ?>" class="btn btn-primary">Read more</a>
</article>
<?php
endwhile;
else :
?>
<p>No posts found</p>
<?php endif; ?>
</div>
<div class="col-md-4">
<?php get_sidebar(); ?>
</div>
</div>
</div>
<?php get_footer(); ?>
<?php get_header(); ?> <div class="container mt-5"> <div class="row"> <div class="col-md-8"> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <article <?php post_class('mb-5'); ?>> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <p class="text-muted"><?php the_date(); ?> by <?php the_author(); ?></p> <?php the_excerpt(); ?> <a href="<?php the_permalink(); ?>" class="btn btn-primary">Read more</a> </article> <?php endwhile; else : ?> <p>No posts found</p> <?php endif; ?> </div> <div class="col-md-4"> <?php get_sidebar(); ?> </div> </div> </div> <?php get_footer(); ?>
<?php get_header(); ?>

<div class="container mt-5">
    <div class="row">
        <div class="col-md-8">
            <?php
            if (have_posts()) :
                while (have_posts()) :
                    the_post();
            ?>
                    <article <?php post_class('mb-5'); ?>>
                        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                        <p class="text-muted"><?php the_date(); ?> by <?php the_author(); ?></p>
                        <?php the_excerpt(); ?>
                        <a href="<?php the_permalink(); ?>" class="btn btn-primary">Read more</a>
                    </article>
            <?php
                endwhile;
            else :
            ?>
                <p>No posts found</p>
            <?php endif; ?>
        </div>
        <div class="col-md-4">
            <?php get_sidebar(); ?>
        </div>
    </div>
</div>

<?php get_footer(); ?>

We have created an example, using different available WordPress hooks and actions to display the different sections. It’s not complicated, we just need to place each element where it belongs (here is a list of all of them https://developer.wordpress.org/plugins/hooks/)Reading time: 2 minutes

Hello, today we are going to learn how to create a WordPress theme using PHP + HTML + CSS + Javascript and we won’t die trying.

We are going to create a foundation upon which we can build different themes, and we’ll also use Bootstrap as a design library.

First, we need to have WordPress installed on our machine. In my case, I’m using Docker.

Now let’s start creating the theme. To do this, we’ll create the folder for our theme within wp-content/themes/. In my case, I’ll name it customtheme.

Now let’s add the different base files for our theme.

We create style.css with the following content:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/*
Theme Name: My Custom Theme
Description: A custom theme for my site.
Version: 1.0
Author: Your Name
*/
/* Global styles can go here */
body {
background-color: #f8f9fa;
color: #343a40;
}
.container {
background-color: #ffffff;
border: 1px solid #dee2e6;
border-radius: 5px;
padding: 20px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
}
h2 {
color: #007bff;
}
.text-muted {
font-size: 14px;
}
.btn-primary {
background-color: #007bff;
border-color: #007bff;
}
.btn-primary:hover {
background-color: #0056b3;
border-color: #0056b3;
}
/* Theme Name: My Custom Theme Description: A custom theme for my site. Version: 1.0 Author: Your Name */ /* Global styles can go here */ body { background-color: #f8f9fa; color: #343a40; } .container { background-color: #ffffff; border: 1px solid #dee2e6; border-radius: 5px; padding: 20px; box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1); } h2 { color: #007bff; } .text-muted { font-size: 14px; } .btn-primary { background-color: #007bff; border-color: #007bff; } .btn-primary:hover { background-color: #0056b3; border-color: #0056b3; }
/*
Theme Name: My Custom Theme
Description: A custom theme for my site.
Version: 1.0
Author: Your Name
*/

/* Global styles can go here */
body {
    background-color: #f8f9fa;
    color: #343a40;
}

.container {
    background-color: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 5px;
    padding: 20px;
    box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
}

h2 {
    color: #007bff;
}

.text-muted {
    font-size: 14px;
}

.btn-primary {
    background-color: #007bff;
    border-color: #007bff;
}

.btn-primary:hover {
    background-color: #0056b3;
    border-color: #0056b3;
}

Here we will add the different styles for our theme.

Now let’s create the index.php file.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php get_header(); ?>
<div class="container mt-5">
<div class="row">
<div class="col-md-8">
<?php
if (have_posts()) :
while (have_posts()) :
the_post();
?>
<article <?php post_class('mb-5'); ?>>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="text-muted"><?php the_date(); ?> by <?php the_author(); ?></p>
<?php the_excerpt(); ?>
<a href="<?php the_permalink(); ?>" class="btn btn-primary">Read more</a>
</article>
<?php
endwhile;
else :
?>
<p>No posts found</p>
<?php endif; ?>
</div>
<div class="col-md-4">
<?php get_sidebar(); ?>
</div>
</div>
</div>
<?php get_footer(); ?>
<?php get_header(); ?> <div class="container mt-5"> <div class="row"> <div class="col-md-8"> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <article <?php post_class('mb-5'); ?>> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <p class="text-muted"><?php the_date(); ?> by <?php the_author(); ?></p> <?php the_excerpt(); ?> <a href="<?php the_permalink(); ?>" class="btn btn-primary">Read more</a> </article> <?php endwhile; else : ?> <p>No posts found</p> <?php endif; ?> </div> <div class="col-md-4"> <?php get_sidebar(); ?> </div> </div> </div> <?php get_footer(); ?>
<?php get_header(); ?>

<div class="container mt-5">
    <div class="row">
        <div class="col-md-8">
            <?php
            if (have_posts()) :
                while (have_posts()) :
                    the_post();
            ?>
                    <article <?php post_class('mb-5'); ?>>
                        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                        <p class="text-muted"><?php the_date(); ?> by <?php the_author(); ?></p>
                        <?php the_excerpt(); ?>
                        <a href="<?php the_permalink(); ?>" class="btn btn-primary">Read more</a>
                    </article>
            <?php
                endwhile;
            else :
            ?>
                <p>No posts found</p>
            <?php endif; ?>
        </div>
        <div class="col-md-4">
            <?php get_sidebar(); ?>
        </div>
    </div>
</div>

<?php get_footer(); ?>

We have created an example, using different available WordPress hooks and actions to display the different sections. It’s not complicated, we just need to place each element where it belongs (here is a list of all of them https://developer.wordpress.org/plugins/hooks/)

Now let’s create the header.php file.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo('charset'); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php wp_title(); ?></title>
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<!DOCTYPE html> <html <?php language_attributes(); ?>> <head> <meta charset="<?php bloginfo('charset'); ?>"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title><?php wp_title(); ?></title> <?php wp_head(); ?> </head> <body <?php body_class(); ?>>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
    <meta charset="<?php bloginfo('charset'); ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php wp_title(); ?></title>
    <?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>

And footer.php

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php wp_footer(); ?>
</body>
</html>
<?php wp_footer(); ?> </body> </html>
<?php wp_footer(); ?>
</body>
</html>

Finally, let’s create the functions.php file and add the styles of our theme and Bootstrap

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php
function customtheme_enqueue_styles() {
wp_enqueue_style('customtheme-style', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts', 'customtheme_enqueue_styles');
function enqueue_bootstrap() {
wp_enqueue_style('bootstrap-css', 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css');
}
add_action('wp_enqueue_scripts', 'enqueue_bootstrap');
<?php function customtheme_enqueue_styles() { wp_enqueue_style('customtheme-style', get_stylesheet_uri()); } add_action('wp_enqueue_scripts', 'customtheme_enqueue_styles'); function enqueue_bootstrap() { wp_enqueue_style('bootstrap-css', 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css'); } add_action('wp_enqueue_scripts', 'enqueue_bootstrap');
<?php
function customtheme_enqueue_styles() {
    wp_enqueue_style('customtheme-style', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts', 'customtheme_enqueue_styles');

function enqueue_bootstrap() {
    wp_enqueue_style('bootstrap-css', 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css');
}
add_action('wp_enqueue_scripts', 'enqueue_bootstrap');

And now let’s go to our WordPress and we will see an inactive theme without a photo.

We activate it, and we can see the result:

It’s nothing extraordinary, but it’s a foundation that we can use to improve the theme and create a new one.

Now we create the functions.php file and add the styles of our theme and Bootstrap:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php
function customtheme_enqueue_styles() {
wp_enqueue_style('customtheme-style', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts', 'customtheme_enqueue_styles');
function enqueue_bootstrap() {
wp_enqueue_style('bootstrap-css', 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css');
}
add_action('wp_enqueue_scripts', 'enqueue_bootstrap');
<?php function customtheme_enqueue_styles() { wp_enqueue_style('customtheme-style', get_stylesheet_uri()); } add_action('wp_enqueue_scripts', 'customtheme_enqueue_styles'); function enqueue_bootstrap() { wp_enqueue_style('bootstrap-css', 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css'); } add_action('wp_enqueue_scripts', 'enqueue_bootstrap');
<?php
function customtheme_enqueue_styles() {
    wp_enqueue_style('customtheme-style', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts', 'customtheme_enqueue_styles');

function enqueue_bootstrap() {
    wp_enqueue_style('bootstrap-css', 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css');
}
add_action('wp_enqueue_scripts', 'enqueue_bootstrap');

And now we go to our WordPress and we will see a theme without activation and without a photo.

We activate it, and we can see the result:

It’s nothing extraordinary, but it’s a foundation that we can use to improve the theme and create a new one.

It’s nothing extraordinary, but it’s a foundation that we can use to improve the theme and create a new one.

0

Leave a Comment