WordPress theme development tutorial step by step

WordPress theme development tutorial step by step

WordPress theme development tutorial step by step

WordPress is the best cms for blog type or to make a simple dynamic site, so in this wordpress theme development tutorial we will learn how to make a wp theme from the scratch step by step from an html file and which is installable to any wordpress site,

The steps of the WordPress theme development tutorial

The steps of the WordPress theme development tutorial

The steps of the WordPress theme development tutorial

First step is install wordpress

install wordpress by following the steps described below, the first step of WordPress theme development tutorial is install wordpress.

  1.  download wordpress from the wordpress.org website and then
  2. turn on your local server and mysql to install in localhost or login to your cpanel to install in a server,
  3. create a database with database name, username, password and hostname
  4. place the unzipped downloaded folder to your host folder (if you are using localhost and xampp then it will be htdocs, if you are using wampp then it will be www or if you are using server then place it to public html folder)
  5. now run the project in browser
  6. now install the downloaded wordpress by entering the fields data.

To read in details click here….

 

Second Step devide the html files

To develop a wordpress theme from html first need a html template which have to convert into wordpress theme and for that get the html files with css, js, images files and folder and copy them and then go to your project folder and create a folder and rename it according to your theme name and paste the coppied filed inside it. its the second step of WordPress theme development tutorial.

wordpress theme development tutorial from scratch split html

split html

  1. after pasting the files,
  2. open the home page in a html or code editor,
  3. select the common portion for header , footer and sidebar,
  4. then create 4 files in your theme folder and give name as header.php, footer.php , sidebar.php, and index.php ,
  5. paste the header portions html to the header.php file,
  6. similarly paste the footer portions html to the footer.php file
  7. and  paste the sidebar portions html to the sidebar.php file
  8. and paste the rest of the html portion to index.php file,
  9. now get the header by gate header(); function ,
  10. get footer by using get_footer() function
  11. and get sidebar by calling function get_sidebar(); inside <?php  ?> tag

To read in details click here….

 

Third make style.css file to define the theme

in this WordPress theme development tutorial in this part we are going to learn about theme defining file. If we logged in to the admin panel we will see that there is a broken theme as to make a wordpress there should be at the a index.php file and a style.css file in your theme folder, the style.cc file is used to define a wordpress theme so lest start to create a theme style file

  1. first create a style.css file in your theme folder,
  2. make a comment portion and rite there the below code
  3. /* Theme Name: Twenty Fifteen Theme URI: https://wordpress.org/themes/twentyfifteen/ Author: the WordPress team Author URI: https://wordpress.org/ Description: Our 2015 default theme is clean, blog-focused, and designed for clarity. Twenty Fifteen’s simple, straightforward typography is readable on a wide variety of screen sizes, and suitable for multiple languages. We designed it using a mobile-first approach, meaning your content takes center-stage, regardless of whether your visitors arrive by smartphone, tablet, laptop, or desktop computer. Version: 1.6 License: GNU General Public License v2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html Tags: blog, two-columns, left-sidebar, accessibility-ready, custom-background, custom-colors, custom-header, custom-logo, custom-menu, editor-style, featured-images, microformats, post-formats, rtl-language-support, sticky-post, threaded-comments, translation-ready Text Domain: twentyfifteen */
  4. do not change the text of left side of colon they are used as keyword example Theme Name must not be changed ,
  5. change the right side content of colon as twenty fiften
  6. and you have done a theme style.css

To read in details click here….

 

Fourth make theme functions file

The fourth step of the WordPress theme development tutorial is making a theme functions. The theme functions is used to write all the functions to be used only for the theme like to include script to frontend or backend we can use functions.php file or to define menu, dynamic sidebar, or custom post we are use to use wordpress theme function.php file.

  1. open your theme folder ,
  2. create a php file and give its name as functions.php

To read in details click here….

 

Fifth make screenshot.png file for theme featured image

Again if you login to the admin panel and visit the appearance -> theme you can be able to find your theme but there is no image like other default theme showing and to make that featured image need to follow the steps

wordpress theme development tutorial from scratch

  1. take a screen shot of your html design ,
  2. save the image in png format,
  3. rename the file to   screenshot.png,
  4. move the screenshot.png file in your theme folder
  5. and you have done.

To read in details click here….

Sixth make a theme option page for logo , social media, copyright note etc.

Of any wordpress theme development tutorial a vital point is theme option page developers use to find many plugin or code to make theme option but here is a very easy method to make a theme option page from your function.php file by writing some functions and hooks. for that follow the steps and for details click on the link provided below.

wordpress theme development tutorial from scratch theme option panel

Theme Option Panel

  1. Create a menu and page in wordpress admin panel following the below code.
  2. Now declare the function and basic html and code , called by the declaration of theme option menu
  3. Initialize the display of the field,
  4. make the field functional
  5. there is a details link and sample code for theme option page
//call the function for admin menu
add_action("admin_menu", "add_theme_menu_item");
//called function by admin menu
function add_theme_menu_item()
{
$page_title       = 'Theme Option Page';
$menu_title       = 'Theme Option';
$capability       = 'manage_options';
$menu_slug        = 'theme-panel';
$function_to_call = 'theme_settings_page';
$icon_url         = null;
$position         = 12;
add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function_to_call, $icon_url, $position);
}
 
//The function to call from the time of adding admin menu
function theme_settings_page(){
?>
<div class="wrap">
<h1>Theme Options</h1>
<form method="post" action="options.php">
<?php
//giving the id of the field area
settings_fields("section");
do_settings_sections("theme-options");
submit_button();
?>
</form>
</div>
<?php
}
 
//call the function for admin init
add_action("admin_init", "display_theme_panel_fields");
//called function by admin init
function display_theme_panel_fields()
{
add_settings_section("section", "All Settings", null, "theme-options");
 
//adding the secrtion of logo url
add_settings_field("theme_logo_url", "Theme Logo Url", "display_theme_logo_element", "theme-options", "section");
//registering the secrtion of logo url
register_setting("section", "theme_logo_url");
 
//adding the secrtion of Header Email Address
add_settings_field("theme_header_email", "Theme Header Email Address", "display_theme_header_email", "theme-options", "section");
//registering the secrtion of Header Email Address
register_setting("section", "theme_header_email");
}
//display the section for logo url
function display_theme_logo_element()
{
?><input type="text" name="theme_logo_url" id="theme_logo_url" value="<?php echo get_option('theme_logo_url'); ?>" style="width:100%;"/><?php
}
//display the section for Header Email Address
function display_theme_header_email()
{
?><input type="text" name="theme_header_email" id="theme_header_email" value="<?php echo get_option('theme_header_email'); ?>" style="width:100%;"/><?php
}

To read in details click here….

 

The steps of the WordPress theme development tutorial

The steps of the WordPress theme development tutorial

Seventh create the theme header portion dynamic

in wordpress the theme header must have to configure properly for the uses for seo and title charset and language also to get the theme style wordpress default code for header and for pingback url and for that follow the below instructions:

  1. The code or function <html <?php language_attributes(); ?>> is used in the starting html tag for the language of the site.
  2. <meta charset="<?php bloginfo( 'charset' ); ?>"> is used to get the html default charset.
  3. <title><?php wp_title ( '' ); if (is_home ()) { bloginfo ( 'name' ); echo ' - '; bloginfo ( 'description' ); } ?></title> is used for get the page title according to the site name and page name and description.
  4. <link href="<?php echo get_stylesheet_uri(); ?>" rel="stylesheet" /> is used for getting the theme defining style.css file which is located in theme root folder.
  5. <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>"> is used to get the pingback url
  6. <?php wp_head(); ?> is used to get the default header portion as css some js of wordpress .
  7. <?php body_class(); ?> is used to define the unic body class for each pages it also generated some default classes of wordpress body.
  8. To include the other css located in the theme directory include from theme style.css ehich is located in the root directory of the theme defining the theme. Or place <?php echo get_bloginfo ( 'template_url' ) . '/' ?> to give the theme url or its links.

To read in details click here….

 

No Eight Have to make the theme menu dynamic


main nav menu is the most important part of a website and in a wordpress theme there should be a dynamic nav menu so in this part of wordpress theme development tutorial we will learn how to develop a dynamic menu in wordpress and for thet follow the steps and you can read details from below link

wordpress theme development tutorial from scratch theme menu

Theme Menu

  1. first  declare the menu in theme function
  2. //To register nav menu
    function register_my_menus() {
    $menu_args = array(
    'main_menu' => __( 'Main Menu' ),
    'footer_menu' => __( 'Footer Menu' )
    );
    register_nav_menus($menu_args);
    }
    
    add_action( 'init', 'register_my_menus' );
  3. then call the menu from the frontend code by using the function
  4. <?php
    //The Arguments of the menu
    $args = array(
    'menu' => '',
    'container' => 'div',
    'container_class' => '',
    'container_id' => '',
    'menu_class' => 'menu',
    'menu_id' => '',
    'echo' => true,
    'fallback_cb' => 'wp_page_menu',
    'before' => '',
    'after' => '',
    'link_before' => '',
    'link_after' => '',
    'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
    'item_spacing' => 'preserve',
    'depth' => 0,
    'walker' => '',
    'theme_location' => 'main_menu'                           
    );
    
    //to display the menu
    wp_nav_menu( $args );
    ?>

To read in details click here….

Nine Declare theme footer

in theme footer we have to call the default code of wordpress for footer as there is many plugin and wordpress itself sending many script and code through the footer and for that before ending body tag use the code <?php wp_footer(); ?>

wordpress theme development tutorial from scratch dynamic footer

Dynamic Footer

To read in details click here….

 

Tenth Declare sidebar with widget

through the wordpress theme development tutorial we will make many sidebar for footer and sidebar and for that we need to go to the functions.php file and declare a sidebar first and then have to call the sidebar in frontend so do that step by step

wordpress theme development tutorial from scratch dynamic sidebar

Dynamic Sidebar

  1. declare sidebar in functions.php file
  2. //To Register a sidebar
    function theme_slug_widgets_init() {
    register_sidebar( array(
    'name'          => __( 'Main Sidebar', 'theme-slug' ),
    'id'            => 'sidebar-1',
    'description'   => __( 'Widgets in this area will be shown on all posts and pages.', 'theme-slug' ),
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget'  => '</li>',
    'before_title'  => '<h2 class="widgettitle">',
    'after_title'   => '</h2>',
    ) );
    }
    
    add_action( 'widgets_init', 'theme_slug_widgets_init' );
  3. call the sidebar in front end
  4. <?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
    <ul id="primary-sidebar" class="primary-sidebar widget-area" role="complementary">
    <?php dynamic_sidebar( 'sidebar-1' ); ?>
    </ul><!-- #primary-sidebar -->
    <?php endif; ?>

To read in details click here….

Eleventh make a custom post type for the slider or testimonials or any repeater type post

in wordpress development the custom post type is very important and using that we can create many admin post type menu and fetch them to the front end and for that follow the steps

  1. first declare the custom field of functions.php file
  2. function custom_slider_init(){
    $labels = array(
    'name'               => ' Sliders',
    'singular_name'      => ' Slider ',
    'menu_name'          => ' Sliders',
    'name_admin_bar'     => ' Slider ',
    'add_new'            => 'Add Slider ',
    'add_new_item'       => 'Add New Slider ',
    'new_item'           => 'New Slider ',
    'edit_item'          => 'Edit Slider ',
    'view_item'          => 'View Slider ',
    'all_items'          => 'All Sliders ',
    'search_items'       => 'Search Sliders',
    'parent_item_colon'  => 'Parent Sliders',
    'not_found'          => 'No Sliders found.',
    'not_found_in_trash' => 'No Sliders  found in Trash.'
    );
     
    $args = array(
    'labels'             => $labels,
    'description'        => __( 'Description.', 'your-plugin-textdomain' ),
    'public'             => true,
    'publicly_queryable' => true,
    'show_ui'            => true,
    'show_in_menu'       => true,
    'query_var'          => true,
    'rewrite'            => array( 'slug' => 'sliders' ),
    'capability_type'    => 'post',
    'has_archive'        => true,
    'hierarchical'       => false,
    'menu_position'      => null,
    'supports'           => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'post-formats', 'custom-fields' )
    );
     
    register_post_type( 'custom_slider', $args );
    }
     
    add_action( 'init', 'custom_slider_init' );
  3. then fetch the custom post types post in frontend
  4. //the argument for the post
    $args = array(  'post_type' => 'product'    );
    
    //passing the argument through query post
    query_posts( $args );
     
    // if there is post go inside if loop
    if ( have_posts() ):
    //fetch the cumber of posts
    while ( have_posts() ) :
    the_post();
     
    // Do stuff with the post content.
    the_title();
    the_permalink();
    the_content();
    the_excerpt();
    echo wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    echo get_the_category_list();
    endwhile;
    else:
    // Insert any content or load a template for no posts found.
    endif;
    // reset the query for the other posts have declared and to be declare
    wp_reset_query();

To read in details click here….

The steps of the WordPress theme development tutorial

The steps of the WordPress theme development tutorial

 

12ve Make a page template

now develop a page template for the wordpress theme , it will be used as a default page template to call any page , that is if you have not selected any custom page template for the page it will displayed through the page.php file now lets make it step by step

Single custom post

Single custom post

  1. first create a php file in your theme folder and give its name page.php the name spelling must have to page.php
  2. Then for get the header write the code get_header();
  3. and to get the footer portion write the code get_footer()
  4. and then write the code get_sidebar(); to get the sidebar in its position
  5. write if(have_posts()): the_post(); endif to get the post data
  6. now get the page title and print it by using the_title(); code
  7. and get the content by using the_content(); code
  8. and you can use the code echo wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); to print the thumbnail image url

To read in details click here….

13th Make a single template template

the single.php file is used to show wordpress posts and for that we need to flow some step

first go to the theme folder and create a php file by name single.php

then follow the process of page development

To read in details click here….

 

14th Make custom  post and page template

to develop a wordpress theme sometime we need to make deffarent page and post with different design so we need to create custom post and page template

to develop a custom page template in wordpress

  1. go to your theme folder and create a php file give it any name and inside php tag in comment declare its name
  2. <?php /* * Template Name: Contact Us */ ?>
  3. and then follow the normal page creation steps

    To read in details click here….

to develop a custom post template in wordpress

  1. go to your theme folder and create a php file give it post-<post-slag>.php name
  2. and then follow the normal page creation steps

To read in details click here….

15th Now develop a search page

in WordPress theme development a search page is very important as someone search from search form it will show all related website data and for that

  1. go to your theme folder and create a php file by name search.php
  2. and then write a loop if(have_posts()): while(have_posts()): the_post(); endwhile; endif;
  3. and inside the while loop you can follow the steps of page or post creation to get the title content and image
  4. and you can also get the header, footer and sidebar by following the page or post development

To read in details click here….

16th Make a custom archive page template

an archive page is displaying the date wise or category wise data and to make a archive page and as archive page took a vital place so we have made another post for that in the WordPress theme development tutorial.

  1. first go to your theme folder and make a php file by name archive.php
  2. and then follow the steps of search page development

To read in details click here….

 

17 now make a 404.php page

if any url is not found in your site then wordpress use to display the 404.php file and to make a 404.php file

  1. go to your theme folder and create a php file and give its name 404.php
  2. now get the header, footer and sidebar
  3. and write 404 page not found

 

WordPress theme development tutorial step by step from the scratch at a glance

To development WordPress theme there is needed 13 mandatory files and they are as described below. and we have discussed through the WordPress theme development tutorial

  1. functions.php
  2. index.php
  3. style.css
  4. screenshot.png
  5. header.php
  6. footer.php
  7. page.php
  8. single.php
  9. sidebar.php
  10. archive.php
  11. commentform.php
  12. search.php
  13. and 404.php

the functions of above pages at a glance which we have seen through the WordPress theme development tutorial step by step from the scratch

Now going to tell you the uses of mandatory fields

the page functions.php is used for write the functions of the page like custom post, define menu, make theme support for thumbnails , declare side menu etc.

The page index.php is used as a default front page will show id a static front page is not defined.

The page header.php is used as header to call in every page.

The page footer.php is used as footer to call in every page.

The file page.php is used as a default page template if you want to use some different page template then you have to create page template.

The file single.php is used as a template to show single posts.

sidebar.php file is used as a sidebar can be called from any pages.

The file archive.php is used as a template to show the category or date wise posts.

The file commentform.php is used to make a comment form and showing comment.

The page file search.php is used to show the searched posts or pages.

And if not a page or post is found in url then 404.php file is called as atemplate

The file style.css is used for define a theme name , version, descriptions, author name, theme url, author url etc.

screenshot.png file is used to show the grafics ciew at admin panels theme section.

 

The steps of the WordPress theme development tutorial

The steps of the WordPress theme development tutorial

 

I hope that WordPress theme development tutorial step by step from the scratch post helped you to make a wordpress theme and you have learned to develop wordpress. and for any query you can comment below. I have given all the details page link in each portion for WordPress theme development please go to there and read in details.

 

Thanks for Reading

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.