WordPress
WordPress Interview Questions and Answers
Section 1: WordPress Basics (Q1–Q20)
Q1. What is WordPress?
A1. WordPress is a free and open-source content management system (CMS) written in PHP and paired with a MySQL or MariaDB database. It is widely used for creating websites and blogs.
Q2. What are WordPress themes?
A2. Themes control the visual appearance of a WordPress site. Example:
// To get the current theme name
echo wp_get_theme()->get('Name');
Q3. What are WordPress plugins?
A3. Plugins are extensions that add functionality to WordPress.
// Example: Activate a plugin programmatically
activate_plugin('plugin-directory/plugin-file.php');
Q4. Difference between Posts and Pages?
A4. Posts are timely blog entries, Pages are static content like About or Contact pages.
Q5. What is a WordPress Hook?
A5. Hooks allow you to add or change WordPress functionality.
// Example of action hook
do_action('init');
// Example of filter hook
apply_filters('the_content', $content);
Q6. Difference between Action and Filter Hook?
A6. Actions execute code at specific points; Filters modify data before it is used.
Q7. What is the WordPress loop?
A7. The loop is PHP code that displays posts.
if (have_posts()) {
while (have_posts()) {
the_post();
the_title();
the_content();
}
}
Q8. What are WordPress Widgets?
A8. Widgets are blocks that add content to sidebars, footers, etc.
Q9. What is a shortcode in WordPress?
A9. Shortcodes are placeholders for dynamic content.
// Example: Create a shortcode
function my_shortcode() {
return "Hello World";
}
add_shortcode('greet', 'my_shortcode');
Q10. Difference between Categories and Tags?
A10. Categories are hierarchical and broader; tags are non-hierarchical keywords.
Q11. What is wp-config.php?
A11. Core configuration file for database, keys, and debug settings.
Q12. How to enable debug mode in WordPress?
A12.
define('WP_DEBUG', true);
Q13. What are custom post types?
A13. Custom content types like Portfolio, Products.
register_post_type('portfolio', [
'public' => true,
'label' => 'Portfolios'
]);
Q14. What are taxonomies?
A14. Taxonomies categorize content. Default are category and tag.
Q15. What is the difference between WP_Query and get_posts()?
A15. WP_Query is more flexible and allows pagination; get_posts() is simpler.
Q16. How to create a child theme?
A16.
/* style.css */
/*
Theme Name: My Child Theme
Template: parent-theme-folder
*/
Q17. Difference between include() and require()?
A17. require() stops execution if file missing; include() gives warning and continues.
Q18. What is REST API in WordPress?
A18. REST API allows access and manipulation of WordPress data using HTTP requests.
Q19. How to schedule a cron job in WordPress?
A19.
if (!wp_next_scheduled('my_cron_job')) {
wp_schedule_event(time(), 'hourly', 'my_cron_job');
}
add_action('my_cron_job', 'my_cron_function');
Q20. How to secure a WordPress website?
A20. Use strong passwords, two-factor authentication, security plugins, SSL, limit login attempts.
Section 2: WooCommerce Basics (Q21–Q40)
Q21. What is WooCommerce?
A21. WooCommerce is a free WordPress plugin that allows you to sell products online.
Q22. How to install WooCommerce?
A22. Install via Plugins > Add New in WordPress, then activate.
Q23. Difference between Simple, Grouped, Variable Products?
A23.
-
Simple: Single product
-
Grouped: Multiple related products
-
Variable: Products with variations (size, color)
Q24. How to add a new product programmatically?
A24.
$product = new WC_Product_Simple();
$product->set_name('Sample Product');
$product->set_regular_price(20);
$product->save();
Q25. What are WooCommerce hooks?
A25. Hooks allow customizing WooCommerce functionality.
add_action('woocommerce_before_shop_loop', 'my_custom_message');
function my_custom_message() {
echo '<p>Welcome to our store!</p>';
}
Q26. How to add custom fields to WooCommerce products?
A26. Use woocommerce_product_options_general_product_data
action.
Q27. How to create custom checkout fields?
A27.
add_filter('woocommerce_checkout_fields', 'custom_checkout_fields');
function custom_checkout_fields($fields) {
$fields['billing']['billing_custom'] = [
'label' => 'Custom Field',
'required' => true
];
return $fields;
}
Q28. How to add custom product tabs?
A28.
add_filter('woocommerce_product_tabs', 'custom_product_tab');
function custom_product_tab($tabs) {
$tabs['custom_tab'] = [
'title' => 'Custom Info',
'callback' => 'custom_tab_content'
];
return $tabs;
}
function custom_tab_content() {
echo '<p>Custom tab content here.</p>';
}
Q29. How to create a coupon programmatically?
A29.
$coupon = new WC_Coupon();
$coupon->set_code('DISCOUNT10');
$coupon->set_amount(10);
$coupon->save();
Q30. How to modify WooCommerce email templates?
A30. Copy template from woocommerce/templates/emails/
to your theme and modify.
Q31. What are WooCommerce shortcodes?
A31. Shortcodes display WooCommerce content, e.g., [products limit="4" columns="4"]
Q32. How to track WooCommerce orders programmatically?
A32.
$order = wc_get_order($order_id);
$status = $order->get_status();
Q33. How to add custom payment gateway?
A33. Extend WC_Payment_Gateway
class and register it.
Q34. How to restrict products by user role?
A34. Use hooks like woocommerce_product_query
and current_user_can()
.
Q35. How to hide prices for non-logged-in users?
A35.
add_filter('woocommerce_get_price_html', 'hide_price_if_not_logged_in');
function hide_price_if_not_logged_in($price) {
if (!is_user_logged_in()) return 'Login to see price';
return $price;
}
Q36. How to create a subscription product?
A36. Requires WooCommerce Subscriptions plugin; define product as subscription type.
Q37. How to apply tax rules in WooCommerce?
A37. WooCommerce > Settings > Tax; programmatically use WC_Tax
class.
Q38. How to create a WooCommerce custom order status?
A38.
add_action('init','register_custom_order_status');
function register_custom_order_status(){
register_post_status('wc-shipped', [
'label' => 'Shipped',
'public' => true,
'show_in_admin_status_list' => true
]);
}
Q39. How to change the number of products per page?
A39.
add_filter('loop_shop_per_page', 'products_per_page', 20);
function products_per_page($cols) {
return 12;
}
Q40. How to create custom product categories programmatically?
A40.
wp_insert_term('New Category', 'product_cat');
Section 3: Advanced WordPress (Q41–Q60)
Q41. What is the difference between get_template_directory() and get_stylesheet_directory()?
A41. get_template_directory()
returns parent theme path; get_stylesheet_directory()
returns child theme path.
Q42. What are transients in WordPress?
A42. Temporary cached data with expiration.
set_transient('my_transient', 'value', 3600);
$value = get_transient('my_transient');
Q43. How to create a custom WordPress REST API endpoint?
A43.
add_action('rest_api_init', function () {
register_rest_route('myplugin/v1', '/data', [
'methods' => 'GET',
'callback' => 'my_custom_endpoint'
]);
});
function my_custom_endpoint() {
return ['status' => 'success'];
}
Q44. Difference between wp_enqueue_script() and wp_register_script()?
A44. wp_register_script()
registers script; wp_enqueue_script()
adds it to page.
Q45. What are meta boxes in WordPress?
A45. Custom sections in post edit screen.
Q46. How to create custom user roles?
A46.
add_role('custom_role', 'Custom Role', [
'read' => true,
'edit_posts' => false
]);
Q47. What is the difference between options and meta in WordPress?
A47. Options are site-wide; meta is associated with posts, users, or terms.
Q48. How to create a custom taxonomy?
A48.
register_taxonomy('genre', 'book', [
'label' => 'Genre',
'hierarchical' => true
]);
Q49. What is wp_cache in WordPress?
A49. A caching API to store data in memory or external cache.
Q50. How to remove a WordPress version number for security?
A50.
remove_action('wp_head', 'wp_generator');
Q51. Difference between WP_User_Query and get_users()?
A51. WP_User_Query is more flexible, supports pagination.
Q52. How to create a custom login page?
A52. Use wp_login_form()
in a custom template.
Q53. How to redirect after login?
A53.
add_filter('login_redirect', function($redirect_to, $request, $user){
return home_url();
}, 10, 3);
Q54. How to disable XML-RPC in WordPress?
A54.
add_filter('xmlrpc_enabled', '__return_false');
Q55. How to enable WordPress multisite?
A55. Add define('WP_ALLOW_MULTISITE', true);
in wp-config.php, then set up via admin.
Q56. How to create a custom WordPress widget?
A56. Extend WP_Widget
class and register.
Q57. How to enqueue Google Fonts in WordPress?
A57.
wp_enqueue_style('google-fonts', 'https://fonts.googleapis.com/css?family=Roboto', false);
Q58. How to update plugin programmatically?
A58. Use wp_update_plugins()
and update_plugin()
functions.
Q59. How to schedule a one-time event in WordPress?
A59.
wp_schedule_single_event(time()+3600, 'my_one_time_event');
Q60. How to get all posts from a custom post type?
A60.
$args = ['post_type' => 'portfolio', 'posts_per_page' => -1];
$query = new WP_Query($args);
Section 4: Advanced WooCommerce (Q61–Q80)
Q61. How to customize WooCommerce product loop?
A61. Use hooks like woocommerce_before_shop_loop_item
and templates in your theme.
Q62. How to add custom product attributes programmatically?
A62.
wp_set_object_terms($product_id, 'Color', 'pa_color');
Q63. How to add custom product image sizes?
A63.
add_image_size('custom-size', 500, 500, true);
Q64. How to customize the WooCommerce cart page?
A64. Override cart.php
template in your theme.
Q65. How to add fees to WooCommerce checkout?
A65.
add_action('woocommerce_cart_calculate_fees','add_custom_fee');
function add_custom_fee() {
WC()->cart->add_fee('Custom Fee', 5);
}
Q66. How to add custom shipping methods?
A66. Extend WC_Shipping_Method
and register via woocommerce_shipping_methods
filter.
Q67. How to filter WooCommerce products by custom meta field?
A67. Use woocommerce_product_query
hook and meta_query
.
Q68. How to hide certain products from shop page?
A68.
add_action('pre_get_posts','exclude_products');
function exclude_products($q) {
if(!$q->is_main_query() || is_admin()) return;
$q->set('post__not_in', [123, 456]);
}
Q69. How to customize WooCommerce checkout fields order?
A69.
add_filter('woocommerce_checkout_fields','custom_checkout_fields_order');
function custom_checkout_fields_order($fields){
$fields['billing']['billing_phone']['priority'] = 10;
return $fields;
}
Q70. How to create product bundles?
A70. Use WooCommerce Product Bundles plugin or custom logic combining products.
Q71. How to add custom validation in checkout fields?
A71.
add_action('woocommerce_checkout_process','validate_custom_field');
function validate_custom_field(){
if(empty($_POST['billing_custom'])) wc_add_notice('Custom field required', 'error');
}
Q72. How to send custom emails in WooCommerce?
A72. Extend WC_Email
class, register and trigger using hooks.
Q73. How to create custom order meta?
A73.
add_action('woocommerce_checkout_create_order','add_order_meta');
function add_order_meta($order){
$order->update_meta_data('_custom_meta','value');
}
Q74. How to create a WooCommerce report programmatically?
A74. Use WC_Order_Query
and loop through orders to generate report.
Q75. How to remove WooCommerce default scripts and styles?
A75.
add_filter('woocommerce_enqueue_styles','__return_empty_array');
Q76. How to display products by category in a custom template?
A76.
$args = ['post_type'=>'product','tax_query'=>[['taxonomy'=>'product_cat','field'=>'slug','terms'=>'category-slug']]];
$query = new WP_Query($args);
Q77. How to modify WooCommerce price dynamically?
A77. Use woocommerce_product_get_price
filter.
Q78. How to integrate third-party API in WooCommerce checkout?
A78. Use hooks woocommerce_checkout_process
or woocommerce_thankyou
to call API.
Q79. How to add custom button in WooCommerce product page?
A79. Use woocommerce_after_add_to_cart_button
hook.
Q80. How to restrict shipping methods based on products?
A80. Use woocommerce_package_rates
filter and check cart items.
Section 5: Security & Performance (Q81–Q90)
Q81. How to protect WooCommerce from brute force attacks?
A81. Limit login attempts plugin or server rules.
Q82. How to prevent SQL injection in WordPress?
A82. Use $wpdb->prepare()
and proper escaping functions.
Q83. How to improve WooCommerce performance?
A83. Use caching, CDN, optimized images, and object caching.
Q84. How to secure WordPress REST API?
A84. Require authentication or token, use rest_authentication_errors
filter.
Q85. How to force SSL for WooCommerce checkout?
A85. Define FORCE_SSL_ADMIN
as true in wp-config.php.
Q86. How to disable file editing in WordPress?
A86.
define('DISALLOW_FILE_EDIT', true);
Q87. How to block unwanted bots from accessing WordPress?
A87. Use robots.txt or server-level firewall rules.
Q88. How to monitor login attempts in WordPress?
A88. Use security plugins or hooks like wp_login_failed
.
Q89. How to implement object caching in WordPress?
A89. Use Redis or Memcached with WP_Object_Cache
.
Q90. How to minify WooCommerce scripts and styles?
A90. Use plugins like Autoptimize or manually enqueue minified assets.
Section 6: SEO & REST API (Q91–Q100)
Q91. How to make WooCommerce products SEO-friendly?
A91. Use SEO plugins, add meta titles/descriptions, optimize product images.
Q92. How to create custom REST API for WooCommerce products?
A92.
add_action('rest_api_init', function(){
register_rest_route('custom/v1','/products', ['methods'=>'GET','callback'=>'get_products']);
});
function get_products(){
$products = wc_get_products(['limit'=>-1]);
return $products;
}
Q93. How to retrieve orders via REST API?
A93. Use /wp-json/wc/v3/orders
with authentication keys.
Q94. How to add meta fields to REST API response?
A94.
register_rest_field('product','custom_meta', ['get_callback'=>function($object){ return get_post_meta($object['id'],'_custom_meta',true); }]);
Q95. How to make WooCommerce URLs SEO-friendly?
A95. Use permalinks settings and remove default query strings.
Q96. How to improve page speed for WooCommerce?
A96. Lazy load images, use caching, CDN, reduce plugin load.
Q97. How to add breadcrumbs for WooCommerce products?
A97. Use woocommerce_breadcrumb()
function in template.
Q98. How to generate XML sitemap for WooCommerce products?
A98. Use SEO plugins like Yoast or RankMath.
Q99. How to update WooCommerce product stock via REST API?
A99. Send PUT request to /wp-json/wc/v3/products/{id}
with stock_quantity
field.
Q100. How to implement custom search for WooCommerce products?
WP_Query
with meta_query
and tax_query
filters to search by custom fields or categories.