Create a dynamic sidebar using Widget in WordPress

1. Open functions.php file and add the code below:

add_action('widgets_init', 'sidebar_action_name');

2. Then Write the following function at functions.php

function sidebar_action_name() {
	if (function_exists('register_sidebar')) {
			'name' => 'Name-To-Display',
			'before_widget' => '<div class="widget_top">',
			'after_widget' => '</div><div class="widget_foot"></div>',
			'before_title' => '<div class="widget_title">',
			'after_title' => '</div>',

3. Now this is the time to show dynamic sidebar data on UI. Just copy & paste the following code

<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar("Name-To-Display")) : ?>

<?php endif; ?>	

wordpress custom post type and taxonomy

Put these code at function.php file

add_action('init', 'register_post_types_and_taxonomie', 0);

 function register_post_types_and_taxonomie() {
//  New post type 
    $labels = array(
        'name' => _x('Place', 'post type general name'),
        'singular_name' => _x('Place', 'post type general name'),
        'singular_name' => _x('All Place', 'Place type singular name'),
        'add_new' => _x('Add New', 'Place'),
        'add_new_item' => __('Add New Place'),
        'edit_item' => __('Edit Place'),
        'new_item' => __('New Place'),
        'view_item' => __('View Place'),
        'search_items' => __('Search Place'),
        'not_found' => __('Nothing found'),
        'not_found_in_trash' => __('Nothing found in Trash'),
        'parent_item_colon' => ''

    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'menu_icon' => get_stylesheet_directory_uri() . '/sun-small.png',
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title', 'editor', 'thumbnail')

    register_post_type('place_register', $args);

//  Custom Taxonomy for Place
    $labels = array(
        'name' => _x('Place cat', 'taxonomy general name'),
        'singular_name' => _x('Place Category', 'taxonomy singular name'),
        'search_items' => __('Search Place Categories'),
        'all_items' => __('All Place Categories'),
        'parent_item' => __('Parent Place Category'),
        'parent_item_colon' => __('Parent Place Category:'),
        'edit_item' => __('Edit Place Category'),
        'update_item' => __('Update Place Category'),
        'add_new_item' => __('Add New Place Category'),
        'new_item_name' => __('New Place Category'),
        'menu_name' => __('Place Categories'),
    $args = array(
        'labels' => $labels,
        'hierarchical' => true,

    register_taxonomy('category_in_place', 'place_register', $args);


WordPress Reset Password of login user

Reset password of a login user. While resetting a login user password remember you must use the function

See the below example:

     global $userdata;

     if (isset($_POST['submit_resetpass'])) {
         $error = "";
         $success = "";
         $new_password = trim($_POST['new_password']);
         $retype_password = trim($_POST['retype_new_password']);
         $current_user_id = $userdata->ID;
         if( $new_password == $retype_password ){
           wp_set_password($new_password, $current_user_id);
           $success = "Password successfully reset.";
           $error = "Password not matched, please try again.";

How to increase the media upload file size in wordpress

It’s really easy to increase the media upload file size without touching the php.ini file.

Just open your wordpress .htaccess file and paste the following code:

# BEGIN WordPress

  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]

  php_value upload_max_filesize 250M
  php_value post_max_size 250M
  php_value max_execution_time 300
  php_value max_input_time 300

# END WordPress

WordPress, View a PDF file in a webpage

  • First of all create a wordpress template by using the following code:

  Template Name: ViewPDF

header('Content-type: application/pdf');

if (have_posts()) : while (have_posts()) : the_post();

        $args = array(
            'post_type' => 'attachment',
            'numberposts' => 1,
            'post_status' => null,
            'post_parent' => $post->ID

        $attachments = get_posts($args);
        if ($attachments) {
            foreach ($attachments as $attachment) {
                $pdfPath=get_attached_file($attachment->ID, $unfiltered);
	        header('Content-Length: '.filesize($pdfPath));
                echo file_get_contents($pdfPath);


  • Create a new page and select the new created template for this page.
  • Import the pdf file as the page attachment, save the page.
  • That’s it, now browse the new created page to see the PDF file.

How to show all posts from 3 specific category with custom pagination at wordpress

How to show all posts from 3 specific category with custom pagination at wordpress

            $temp = $wp_query;
            $wp_query= null;
            $wp_query = new WP_Query();
            $args = array(
                 'category__in' => array( 18, 19, 20 ),
                 'showposts' => 10,
                 'paged' => $paged,
                 'order' => 'DESC',                               
            $max_page = $wp_query->max_num_pages;
            while ($wp_query->have_posts()): $wp_query->the_post();  

            -- your content goes here --
	    $wp_query = null; $wp_query = $temp; 

            -- Pagination part --
            $prev_title= Prev;
            $next_title=  Next;

How to show Specific category post detail with specific template in wordpress.

Open your single.php in a editor and paste the following code.Update the category according to your desire category in in_category() function and include your desire template.

  if (in_category(array('articles-1','articles-2'))) {
  } elseif (in_category(array('blog-1','blog-2'))) {
  } else{