Create/Register/Display Widget Area To Your Theme Files

Register a new widget area for your website

Past following code on function.php file

Example: Type Your custom widget Name


if (function_exists(‘register_sidebar’)) {


‘name’ => ‘My Widgets’,

‘id’ => ‘my-widgets’,

‘description’ => ‘The my widgets for your website.’,

‘before_widget’ => ‘<div id=”%1$s” class=”widget %2$s”>’,

‘after_widget’ => ‘</div>’,

‘before_title’ => ‘<h2>’,

‘after_title’ => ‘</h2>’


WordPress will add a new Widget area

Call the widget in your theme template php files

Enter this code into your theme files or in the file where you want to display


<?php if (!function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(‘Extra Widgets’)) :


always back up theme files before editing!!!!!!!


How To Create A Child Theme

Why it is Important to work in Child Theme

Child themes allow you to make changes without affecting the original theme’s code, which makes it easy to update your parent theme without erasing your changes. By creating a child theme, you create a separate set of files that you can use to customize the theme without affecting the original theme at all. Not only does this make updating easier, it also makes sure that you will never ruin your original theme as you are never actually modifying the files. You can always turn off your child theme and fall back on the original.

In this example, we will be creating a child theme for our twentytwelve theme. First things first, we need to create a new folder for your child theme. Naming it something like /twentytwelve-child/ is conventional. Within your new theme folder, create a file called style.css and fill in the information as outlined below. The theme Name, URI, Description and Author are totally up to you.

Getting Started

 Theme Name:   Twentytwelve Child
 Theme URI:
 Description:  Twenty Twelve Child Theme
 Author:       Type Your Name
 Author URI:
 Template:     twentytwelve
 Version:      1.0.0
 Tags:         light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
 Text Domain:  twentytwelve-child

@import url("../twentytwelve/style.css");

/* =Theme customization starts here
-------------------------------------------------------------- */

The most important parts of this file are the “Template:

Activating Your Child Theme

Appearances > Themes page in your WordPress Dashboard and activate it.

Get Currentuser Info

<?php global $current_user;

      echo 'Username: ' . $current_user->user_login . "\n";
      echo 'User email: ' . $current_user->user_email . "\n";
      echo 'User first name: ' . $current_user->user_firstname . "\n";
      echo 'User last name: ' . $current_user->user_lastname . "\n";
      echo 'User display name: ' . $current_user->display_name . "\n";
      echo 'User ID: ' . $current_user->ID . "\n";

How To display Pagination with Custom Blog Post

here is code to display pagination on custom blog teplate


$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => 5,
'paged' => $paged,
'post_type' => 'post'
$cpt_query = new WP_Query($args);
if ($cpt_query->have_posts()) : while ($cpt_query->have_posts()) : $cpt_query->the_post();
endwhile; endif;

  • <?php
    previous_posts_link( ‘« PREV’, $cpt_query->max_num_pages) ?>
  • <?php
    next_posts_link( ‘NEXT »’, $cpt_query->max_num_pages) ?>

User is logged in or not.

Display different output depending on whether the user is logged in or not.

Display different output depending on whether the user is logged in or not.

if ( is_user_logged_in() ) {
'Welcome, registered user!';
} else {
'Welcome, visitor!';