WordPress Interview Questions In 2026


1. What is WordPress?

2. Diffrentiate between Post and Page?

3. What is a Child Theme?

/*
Theme Name: Astra Child
Template: astra
*/

4. Differentiate between Parent and Child theme?

5. What is Plugin?

6. How to Create a Plugin?

<?php
/*
Plugin Name: My First Plugin
Description: Simple custom plugin
Version: 1.0
*/


add_action('init', function () {
error_log('Plugin Loaded');
});

7. What is Shortcode?

// 1. Define the function that generates the output
function custom_button_shortcode( $atts ) {
    $a = shortcode_atts( array(
        'url' => '#',
        'text' => 'Click Here',
    ), $atts );

    return '<a class="my-btn" href="' . esc_url($a['url']) . '">' . esc_html($a['text']) . '</a>';
}

// 2. Register the shortcode with WordPress
add_shortcode( 'my_button', 'custom_button_shortcode' );

// Usage in Editor: [my_button url="https://techinterviewhub.in" text="Visit Our Hub"]

8. What is Permalink?

9. What is the WordPress Loop?

10. How do you properly enqueue a JS and CSS file?

function my_custom_scripts() {
    // Enqueue CSS (Handle, URL, Dependencies, Version, Media)
    wp_enqueue_style( 'my-custom-style', get_template_directory_uri() . '/css/custom.css', array(), '1.0.0', 'all' );
    
    // Enqueue JS (Handle, URL, Dependencies, Version, In Footer)
    wp_enqueue_script( 'my-custom-js', get_template_directory_uri() . '/js/custom.js', array('jquery'), '1.0.0', true );
}
// Hook into the 'wp_enqueue_scripts' action
add_action( 'wp_enqueue_scripts', 'my_custom_scripts' );

11. What is the primary role of the wp-config.php file?

12. What are WordPress Hooks?

13. Differentiate between Hooks and Filters?

14.What is ACF ?


Intermediate WordPress Interview Questions

15. Explain all default WordPress Database tables?


Advanced WordPress Interview Questions

How Do You Create a Custom REST API in WordPress and Implement CRUD Operations?

The Setup: Hook and Registration

PHP

// 1. Hook the registration function into 'rest_api_init'
add_action( 'rest_api_init', 'my_custom_api_routes' );

function my_custom_api_routes() {
    // 2. Register the route for a single item, using a regex for the ID
    register_rest_route( 'myplugin/v1', '/data/(?P<id>\d+)', array(
        'methods'               => 'GET, POST, PUT, DELETE', // CRUD
        'callback'              => 'my_handle_data_request',
        // Security check: only users who can edit posts can modify data
        'permission_callback'   => 'current_user_can_edit_posts' 
    ));
}

function current_user_can_edit_posts() {
    return current_user_can( 'edit_posts' );
}

CRUD Operation Callbacks

function my_handle_data_request( $request ) {
    $id = $request['id']; // Get the ID from the URL path
    $method = $request->get_method(); // Get the HTTP method (GET, POST, etc.)
    $params = $request->get_json_params(); // Get data from the request body (for POST/PUT)

    switch ( $method ) {

        case 'GET': // READ
            $post = get_post( $id );
            // Use rest_ensure_response() to wrap the data correctly
            return rest_ensure_response( [
                'id' => $post->ID,
                'title' => $post->post_title,
                // Add more fields here
            ] );

        case 'POST': // CREATE
            // NOTE: POST can also be used for Update
            $new_post_id = wp_insert_post( [
                'post_title'    => sanitize_text_field( $params['title'] ),
                'post_content'  => wp_kses_post( $params['content'] ),
                'post_status'   => 'publish',
                'post_type'     => 'post', 
            ], true );
            
            if ( is_wp_error( $new_post_id ) ) {
                return new WP_REST_Response( ['message' => 'Error creating post.'], 500 );
            }
            return rest_ensure_response( ['id' => $new_post_id], 201 ); // 201: Created

        case 'PUT': // UPDATE
            // Use the ID from the URL to update
            $updated_id = wp_update_post( [
                'ID'            => $id,
                'post_title'    => sanitize_text_field( $params['title'] ),
                // Only include fields you want to change
            ] );
            
            if ( is_wp_error( $updated_id ) ) {
                return new WP_REST_Response( ['message' => 'Update failed.'], 500 );
            }
            return rest_ensure_response( ['success' => true], 200 ); // 200: OK

        case 'DELETE': // DELETE
            // Force delete (skip trash). Set to false to send to trash first.
            $result = wp_delete_post( $id, true ); 
            
            if ( ! $result ) {
                 return new WP_REST_Response( ['message' => 'Delete failed.'], 500 );
            }
            return rest_ensure_response( ['success' => true], 204 ); // 204: No Content

        default:
            return new WP_REST_Response( ['message' => 'Method not allowed.'], 405 );
    }
}

How to Call the API (Client-Side)


Conclusion:-

Stay Ahead in Your Tech Career 🚀

We don’t spam! Read our privacy policy for more info.

Leave a Comment

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

Scroll to Top