Top 10 WordPress interview questions

WordPress is becoming a more powerful CMS. Moreover, WordPress is not only a CMS now. Almost all the companies have WordPress developers along with some other devs and designers. We will cover the top 10 WordPress interview questions in this post. These are the questions every interviewer keeps loaded into their questions gun. If you are a good developer, you probably know the answers to all these top 10 WordPress interview questions. Let’s list them:

How many you have answered in your mind from the above top 10 WordPress Interview questions?

If it’s 7+ then you have a good knowledge of WordPress but if you have answers for all the 10 questions then you can crack the WordPress interview without any problem.

Not sure about the answers for these top 10 WordPress Interview questions? Don’t worry. Have a look at the answers bellow

1. What is wp_enqueue_script in WordPress?

wp_enqueue_script is an action hook provided by WordPress which is used in each and every website. This action hook is made to enqueue the scripts and styles in header.php or footer.php file depending upon the parameters passed to it.

wp_enqueue_script( string $handle, string $src = '', string[] $deps = array(), string|bool|null $ver = false, bool $in_footer = false )

Parameters

1) $handle – (Required)

Name of the script. Should be unique.

2) $src –  (Optional)

Full URL of the script, or path of the script relative to the WordPress root directory.

Default value:

3) $deps – (Optional)

An array of registered script handles this script depends on.

Default value: array()

4) $ver – (Optional)

String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.

Default value: false

5) $in_footer – (Optional)

Whether to enqueue the script before </body> instead of in the <head>. Default ‘false’.

If true passed for $in_footer then the script/style will be loaded in the footer.

2. What will be impact on website if we remove wp_head() function from header.php file?

wp_head() function is used by WordPress to add all the scripts and styles requested by wp_enqueue_script action hook. If we remove the wp_head() function then the styles or scripts will not load. Now the question is which styles and scripts will not load. The answer to this question is the last parameters passed to wp_enqueue_script which tells the action hook about whether to load the resource in the header or footer. So all the styles and scripts will not load that have $in_footer to false.

3. What will be impact on website if we remove wp_footer() function from footer.php file?

From the answer to the above question (Question #2), you might have an answer to this question. Comment your answer in the comments sections.

4. What are Hooks in WordPress and types of hooks?

As we all know that there are some code files of WordPress. These core files use some sort of interdependent code which is used as a bridge between plugins and theme manipulation. This set of codes are called Hooks. 

There are two types of hooks

  • Action
  • Filter

Both the above hooks have one thing in common that is a callback function with some predefined parameters which actually override the default behavior of the hook.

Actions Hook

When the WordPress plugins, theme, or core is being executed then an action hook with a callback is executed to override the current functionality. 

Note that, action hook never returns anything.

Filters hook

Opposite to actions hook, filter hooks are used to modify the data during the execution of plugins or theme code.

5. Theme's which file is used for the WordPress post detail page?

single.php is the file which is used for the post detail page. Best practice is to further use the template parts inside the file so that the same file can be used for custom post type detail pages.

6. How to override Woocommerce template files?

This is a very general WordPress interview question and most of us fail to answer this question because we don’t remember the file path in the plugin and theme.

In woocommerce plugin, all the template files are inside the “woocommerce/templates” folder. To override the template files, we have to create a new folder with the name “woocommerce” inside our active theme folder. 

For example: If our theme name is “mytheme” then the folder structure will be “mytheme/woocommerce“. Inside this folder, we will copy all the template files which we want to override.

7. Write a code to get posts from a custom post type with status publish only

// Custom WP query query
// Query Arguments
$args_query = array(
	'post_type' =&gt; array('testimonial'),
	'post_status' =&gt; array('publish'),
	'posts_per_page' =&gt; -1,
	'ignore_sticky_posts' =&gt; true,
	'order' =&gt; 'DESC',
);

// The Query
$query = new WP_Query( $args_query );

// The Loop
if ( $query-&gt;have_posts() ) {
	while ( $query-&gt;have_posts() ) {
		$query-&gt;the_post();
			// Your custom code
	}
} else {
	// no posts found

}

/* Restore original Post Data */
wp_reset_postdata();

Note: You can also use a code generator from this link

8. What are the minimum required files to create a theme in WordPress

Minimum required file to create a WordPress theme is "style.css". This file should have some comments which are readout by WordPress engine to determine the theme name, author name, description and tags etc.

9. What are the minimum required files to create a custom plugin?

Minimum required file to create a custom plugin is index.php or a file with same name as folder name. This file should have some comments for plugin name, description, author, author url etc.

10. Which action hook you will use if you have to create custom table inside your custom plugin?

register_activation_hook is used to write code which needs to be triggered at the time of plugin activation so we will write our scheme in this action hook.

Want to add some points to these answers?

Use the comments bellow to add your answers or points to these questions.

Share via
Copy link