Create your own WordPress theme from scratch [Part 2]

Here is a basic theme idea, how the things are gonna be arranged in the theme.

basic wordpress theme layout

First, create a empty folder in wordpress’s main directory -> wp-content -> themes, name the new folder as testtheme.

Now create a new css style sheet named style.css and add the below code to it and save it to empty folder of theme.

That css page adds the description and info about theme to wordpress dashboard, that code basically works as theme description. Now, you can see that your new theme is available to be activated from dashboard. Don’t activate it yet, as there no other files in the folder except for the style.css page.

Now create a new PHP file named index.php and save it in same theme directory and activate the theme. After you have activated the theme, refresh wordpress homepage, you will see a blank white page. Because, there is no code in index.php at all. So, now add this code, to index.php to include all sub templates to it.

get_header() : This will include header.php in index page.
get_template_part(‘content’) : This will include content.php in index page.
get_sidebar() : This will include sidebar.php in index page.
get_footer() : This will include footer.php in index page.

Now, Lets code the header.php.

That is a basic code you don’t have to worry much about it or try to edit it, just add this code to header.php and save it.

wp_title() : this function prints the blog title.
bloginfo(‘name’) : this function prints the blog name as configured in dashboard.
bloginfo(‘description’) : this function prints the blog description.
bloginfo(‘stylesheet_url’) : this function prints the current theme style sheet url, style sheet should be named style.css.

So, the above code does the function of setting page title, get stylesheet.
NEXT PART:
CREATE YOUR OWN WORDPRESS THEME FROM SCRATCH [PART 3]

PREVIOUS PART:
CREATE YOUR OWN WORDPRESS THEME FROM SCRATCH [PART 1]