WordPress Interview Questions and Answers

Wordpress interview questions

WordPress is the most usage CMS in the world nowadays, so update knowledge and learning about wordpress is very important if you don’t want to be a fogy developer. If you already dive in to WordPress this article will ask you some question in different level then you can test you got about WordPress powerful CMS.

Let’s start WordPress interview questions

1. How do you get the version of WordPress?

You can get Wordpress's version in wp-includes/version.php

Or you can show it everywhere by using this function

echo bloginfo('version');

2. How to check admin user?

if(is_admin()) {
  // something will be applied to admin
}

3. How many types of hooks do we have in WordPress?

There are two types of hooks in WordPress, they are Action hooks and Filter hooks
– Action hooks: This kind of hook allow you to insert your additional code to the existing one of system, below is one example hook into admin menu. You can check more about WordPress Action reference for more detail

function add_custom_menu() {
  add_menu_page('Custom Menu Title', 'Custom Menu', 'manage_options', 'yourplugin/yourplugin-admin.php', '','dashicons-admin-site', 6);
}
add_action('admin_menu', 'add_custom_menu');

Other common action hooks in WordPress are, you can go here to check out other wordpress function reference

has_action ( string $tag, callable|bool $function_to_check = false )
add_action ( string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1 )
do_action ( string $tag, mixed $arg = '' )
do_action_ref_array()
did_action()
remove_action()
remove_all_action()

– Filter hooks: This kind of hook allow you to only add or replace content or text in post/page, below is one example to hook into WordPress content. You can check more about WordPress filter for more detail

add_filter('the_content', 'wordpress_filter_hook_example');
function wordpress_filter_hook_example($content) {
  return $content. ' Wordpress amazing!'; 
}

Other common filter hooks of WordPress

has_filter ( string $tag, callable|bool $function_to_check = false )
add_filter ( string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1 )
apply_filters ( string $tag, mixed $value )
apply_filters_ref_array()
current_filter()
remove_filter()
remove_all_filters()

4. What is $wpdb and how to use it

$wpdb is a global variable that we can refer to database object. We use it to interact with WordPress database.

function insert_example() {
  global $wpdb;
  $data = array('field_1' => $field1_value, 'field_2' => $field2_value);
  $format = array('%s', '%s');
  $wpdb->insert('table_name', $data, $format);
}

5. What does function wp_enqueue_script do?

wp_enqueue_script is usually used to inject javascript files in HTML. Below is an example

function add_custom_js_script(){
    wp_enqueue_script( 
        'jquery-custom-js-script',
        plugin_dir_url( __FILE__ ).'js/jquery-custom-script.js',
        array('jquery')
    );
}
add_action('wp_enqueue_scripts', 'add_custom_script');

6. Let’s say you have to create a WordPress plugin, what is the most important part?

Plugin headers is the most important in wordpress plugin, without it the plugin in can not run properly.

/*
Plugin Name: My first WordPress plugin
Plugin URI:
Description: Your plugin description
Version: 1.0.1
Author: Author name
-----
*/

7. What will you do if you want to replace a word in all post/page content. For example: Conclusion to Summary

We need to create a function in theme or plugin that will hook into the content, then find the Conclusion text and replace it into Summary.

function change_text($the_content) {
  $the_content = preg_replace('/Conclusion/', 'Summary', $the_content);
  return $the_content;
}
add_filter('the_content', 'change_text');

8. What types of website we should build with WordPress?

WordPress was developed as a blogging CMS in 2003 but now we can create many kind of website with WordPress such as:

  • Photo Gallery website
  • E-Commerce website
  • Informative Website
  • Magazine website
  • Many other kind of website.

You can create your own wordpress theme and plugin or you can easily buy a new amazing wordpress themes that suitable with your purpose.

9. What are the Positive point of WordPress?

WordPress has many Positive aspects for example:

  • Easy to install, upgrade including themes or plugins
  • Built-in SEO engine that you can manage the URL slug, meta data
  • Multiple language support
  • Tons of free/paid themes and plugins that suitable with your purpose
  • Easy to find out the answer for your question when you develop themes, plugins due to huge community in all over the world

10. How to disable the top admin bar at the WordPress front-end?

Very simple, just implement the following code in the functions.php of your theme

add_filter('show_admin_bar', '__return_false');

11. How to send mail in WordPress?

We can easily send mail in WordPress with wp_mail function, we can send either html email or text email, below is an example.

$to = array('contact@webtechsharing.com', 'webtechsharing_fans@example.com', 'support@webtechsharing.com'); 
$subject = 'How to send Email in WordPress'; 
$content = 'Send mail in WordPress is a piece of cake'; 
$headers = array( 'Reply-To' => 'webtechsharing fans <webtechsharing_fans@example.com>');
 
// Set html mail format
add_filter('wp_mail_content_type', 'set_html_content_type');
 
$status = wp_mail($to, $subject, $content,$headers);

12. What are basic the steps to build a WordPress plugin?

  • Choose an unique name, you should check whether plugin existed or not in WordPress org by using plugin search field.
  • Create plugin folder, wp-content/plugins/your_plugin
  • Create main plugin file, wp-content/plugins/your_plugin/your_plugin.php, there are no rule for main plugin file, you can name it whatever you want.
  • Declare your plugin information header to main plugin file
    /*
    Plugin Name: My first WordPress plugin
    Plugin URI:
    Description: Your plugin description
    Version: 1.0.1
    Author: Author name
    */
  • Create sub-folder for PHP file, Translations files, Assets, etc…
  • Create readme.txt file
  • Create uninstall function in your main plugin file or a separate script file

13. How to control the Notice/Warning in WordPress?

Just open wp-config.php file and set WP_DEBUG true/false respectively

define('WP_DEBUG', true);

14. How to make the static text support multiple language translation in WordPress?

There are two ways to do it

// The first way is use __() function
$label = __('Text need to translate', 'text-domain');
// The second way is use _e() function
_e('Text need to translate', 'text-domain'); // This function will print out the translated text
/*
then you need to create .POt file that contain all the text available for translation.
PO stands for Portable Object, you can use POEdit to create the PO file
*/

15. Assuming that we have a WordPress website in folder blog, we want to build a separate page which has 5 post in the main WordPress. How can we do that without making any change in the main WordPress site?

Let’s say we will create a folder Example with the same level as blog folder. In this Example folder we create a php script like this

require_once('../blog/wp-loading.php');
$last5Posts = wp_get_recent_posts(array('numberposts' > 5));
foreach($last5Posts as $post) { 
echo $post["post_title"] . ' ';
}

Related Post

Leave a Reply