Wordpress Advance Interview Questions and Answers

By Dhananjay yadav February 5, 2018
How can we create a CTP in wordpress?
CTP means Custom Post Type. We can create our own custom post types in wordpress besides the default post. We have to use wordpress core to implement this feature. We can add Product type, property type using CTP .
Example is given as follows:
function create_post_type() {
      register_post_type( 'Custom CPT',
          'labels' => array(
            'name' => __( 'Name of your CPT' ),
            'singular_name' => __( 'Name of your CPT' )
          'public' => true,
          'has_archive' => true,
add_action( 'init', 'create_post_type' );

Write custom query to list recent five posts?
Using WP_Query() method we can create custom wordpress queries. An example is given below:
$args = Array('post_type' => 'post', 'posts_per_page' => '5' );
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) : 
   while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <?php endwhile; ?>
<?php else : ?>
    <p> no posts found</p>
<?php endif; ?>

How can we create a widget area?
We can create a widget using the code given in example:
function create_widget() {

    register_sidebar( array(
        'name'          => 'My Widget Area',
        'id'            => 'my_widget',
        'before_widget' => '<div>',
        'after_widget'  => '</div>',
        'before_title'  => '<h2 class="title-widget">',
        'after_title'   => '</h2>',
    ) );

add_action( 'widgets_init', 'create_widget' );

How we will add new navigation menu in footer?
Register a new menu and after calling this menu at proper place in footer template we can add a Footer menu.

How to display menus with container and additional css class?
We can add classes and ids ate the time of dislaying menu. We have to pass the values of parameters in function in wp_nav_menu();

What is the default directory to store images and other files in wordpress uploaded by user?
The default directory to stote files in wordpress is uploads folder. Using wp_upload_dir() we can get the path of current uploading directory.

What is excerpt?
An excerpt is a post summary .Placing a tag
we can create an excert for a post automatically.

How we can get page id or post id in wordpress?
We can use "get_the_ID()" function to get page or post id.
For Example:
      while ( have_posts() ) : the_post();
            echo get_the_ID(); ?>

How we will add a post meta post?
Wordpress has a function add_post_meta(). We can use an unique key to identify this meta for a particular post.

How we will check a logged in user in wordpress?
Wordpress function is_user_logged_in() is used to check logged in user.

What are sort code?
ShortCode is a specific code that allow you to do things with less effort. Shortcode is allow to execute code in post, page, and widget without writing any code. Shortcode can be used directly in post's/page's editor and in widget also.
In php file, shortcode should be called as suggested:
<?php do_shortcode('Here paste your plugin shortcode'); ?> 

Which Text Editor does wordpress use?
WordPress uses the TinyMCE Editor.

Post Tags:

2 comments to ''Wordpress Advance Interview Questions and Answers"