WordPress Theme Development Interview Questions & Answers

Looking for WordPress Interview Questions & Answers about WordPress Theme Development Here is the list of Most Commonly Asked Interview Questions with their answers explained.

What are WordPress Themes?

WordPress theme defines the look and appearance of your website at the front-end, controls the website’s functionalities and workflow, and store the data at the backend.

A WordPress theme is a group of files, which contains different types of files like stylesheets files, templates files, Images and theme’s functionality-related files, etc.


Can I use different layouts in a WordPress theme to display content?

Yes, you can use different layouts in a WordPress theme. You can simply create different layouts for different page templates in a theme.

For Example
Responsive Layout, Full-Width Layout, Page with Sidebar, Page without Sidebar, Different layout for category page, Different Layout for any specific page, Product listing layout for eCommerce website, Product detail layout…etc.


What are the necessary files to create a WordPress theme?

As I said earlier, A WordPress theme can have different and multiple files based upon their layouts, appearance, and functionalities. But At the most basic level, you should have these files to create a WordPress theme.

index.php – Which is the main template file.
styles.css – This is the main stylesheet file.
functions.php – Contains functions and theme’s programming stuff.


What are the template files in WordPress Themes?

A WordPress theme is built with the template files. A template file contains HTML tags, PHP code, and Template Tags.

Template files control how your site’s content to be displayed and how it should look.

A WordPress Theme can have different types of template files like Page templates, Category templates, Archive templates, Custom page templates, Custom post templates…etc.

Page Template will only apply to the pages, Category Template will only apply to the category page and the same goes with others template files.

If there is no template file, then by default index.php will be used to display the content.


What are the Template Tags?

Template tags in WordPress, are the pre-built functions. We can use these functions to retrieve the data from the WordPress database and display within a template file or anywhere in the theme.

Eg:

the_title() – display the title of a page or post.
the_excerpt() – display the summary of a page or post.
the_content() – display the content of a page or post.
the_permalink() – display the URL of that page or post.


What are the template partials?

A template partial is also a template file with a small piece of content, that we use to include within another template file.

Eg: We can create separate templates for header, footer, or sidebar and then can include these template files or template partials within our main template file.

header.php – To generate the site’s header
footer.php – To generate the site’s footer
sidebar.php – To generate the site’s sidebar


What are the most common template files in a WordPress Theme?

In a WordPress theme, there can be multiple template files based upon the design and functionality of that WordPress theme. But here is the list of some of the most common WordPress template files.

header.php – This is the header template file, which contains the site’s headers, meta info, title, etc.

footer.php – This is the footer template file, which contains the site’s footer info.

index.php – This is the main and most required template file of a WordPress theme. each theme should have this file.

style.css – This is the main and required stylesheet file which controls the design and looks of your site.

comments.php – This is a comment template file.

page.php – This is the page template file, which is used when someone requests a page.

single.php – This is the single post template file, which is used when someone requests a single post.

category.php – This is the category template file, which is used when someone requests category page

archive.php – This is the archive template file, which is used when someone requests an archives page.

404.php – This is the page not found template file, which is used when WordPress has not found any post or page or any user requested query.

These are the most common template files, that we can use to create a WordPress theme. Also, there are some other template files, that we can use to create a WordPress theme according to the designs, layouts, and functionalities.


What is post type in WordPress?

In WordPress, Post Type is a type of content. WordPress has different types of content and each content has its own post type.
Example:

  1. Posts have their own post type ‘post’.
  2. Pages have their own post type ‘page’.
  3. Attachments have their own post type ‘attachment’.
  4. Revisions have their own post type ‘revision’.
  5. The navigation menu has its own post type ‘nav_menu_item’.
  6. etc.

What are the default post types in WordPress?

WordPress comes with 5 default post types, each one has its own post type.

  1. Posts
  2. Pages
  3. Attachments
  4. Revisions
  5. Navigation Menu

What are the custom post types in WordPress?

Apart from the default post types, When we create a new post type it’s called custom post type. By using custom post types, we can create our own post types.


What is the loop in WordPress?

The Loop in WordPress is the default way of retrieving data from the database then extract that data for each post and then displaying that data according to the template_tags or theme’s instruction.


What is the use of the functions.php file, why do we use it?

A functions.php is a file, by using this file we can add or edit functionalities in our theme. This file works as a plugin. We can call any pre-built or custom-built functions within this file to add or modify any features in our theme.


What are the Conditional Tags in WordPress?

Conditional Tags in WordPress are the pre-built functions, that we use to display content or perform any action within a specific condition.

Example:

is_home(); – this will check for home page.
is_single(); – this will check for single page.


What is taxonomy?

Taxonomy in WordPress is a way of grouping content and data. By default, WordPress comes with 3 default taxonomies.

  1. Category
  2. Tags
  3. Post Formats

We can also create custom taxonomy like custom post types.


What is Custom taxonomy?

Apart from default taxonomy, when we add another group or taxonomy to arrange content, its called custom taxonomy.


What is Localization?

Localization is the process of translating a theme or plugin and internationalize it.


What are Custom Headers in WordPress Themes?

Custom Headers in WordPress allow the site owner to add an image at the top of the page as a header. We can change the header image via Appearance > customize if the theme has a custom header enabled.


How to add custom header support in your WordPress Theme?

By adding add_theme_support( ‘custom-header’ ); in your theme’s functions.php file, we can easily enable a custom header for our theme.


What is Shortcode in WordPress?

Shortcode in WordPress is a piece of code that allows you to do effective things very easily.

Here I Explained What are Shortcodes and why you should use them in Detail


Which are the default shortcodes that come with WordPress?

WordPress comes with these built-in shortcodes :
[audio]
[video]
[gallery]
[caption]
[playlist]
however, we can create own shortcode through shortcode API.


Why do we use the shortcode?

To execute any code inside WordPress posts, pages, or widgets directly we use shortcodes.

Here I Explained What are Shortcodes and why you should use them in Detail


How to escape shortcode?

Sometimes we just wanted to show the shortcode as it is instead of executing it. To do this we can simply use Two Square brackets.
Example :

[dwp-video] – this will execute video code and display video.
[[dwp-video]] – this will display [dwp-video] as it is.

Escaping Shortcodes in WordPress – Explained in Detail


What is Child Theme in WordPress?

A child theme is a theme that inherits all the functionalities, features, and appearance from its parent theme.


Why We Should Use Child Themes?

Child Theme is the safest way to edit any theme. By using a child theme, we can easily edit the functionalities, features, layout, and appearance of a parent theme without even touching the parent theme’s file. And when the parent theme will get updates, our edits in the child theme will be preserved and applied to the updated parent theme.


What are Custom Fields in WordPress?

Custom Fields in WordPress is a feature that gives us an option to add additional information along with the posts.


What is WordPress Multisite?

WordPress Multisite is a feature in WordPress, that allows us to create and run multiple sites on a single WordPress Installation.


How to enable WordPress Multisite Network?

We can enable WordPress Multisite Network by adding this into the wp-config.php file.

/* Multisite */
define(‘WP_ALLOW_MULTISITE’, true);

How to get the header file in WordPress theme?

To get header file in WordPress theme, we use get_header(); tag. By default, it will get the header.php file.


How to display different header for a specific page in a WordPress theme?

To display different Header for a specific page first will create a different header file and then we will use get_header(‘alias’) tag by passing this header file’s -alias in it as an argument.

Example: Let’s assume we have a file header-shop.php and wanted to show this header file for our shop page, then will use its alias with the function get_header(‘shop’); to display this header for shop page specifically.


How to get the site title within the WordPress theme?

To get the site title in WordPress theme, will use bloginfo(‘name’); tag. This will display the site title.

Note: We can change site title through Settings > General > Site Title via the WordPress admin area.


How to get the site tagline within the WordPress theme?

To get the site tagline in WordPress theme, will use bloginfo(‘description’); tag. This will display the site tagline.

Note: We can change site tagline through Settings > General > Tagline via WordPress admin area.


How to get the site URL within the WordPress theme?

To get the site URL in the WordPress theme, will use bloginfo(‘url’); tag. It will return the site URL.


What is the difference between the Site Address and WordPress Address?

If you ever noticed under Settings > General in WordPress admin area. You must have seen there are two addresses.

  • WordPress address – It is the URL, where your WordPress files exist like /wp-content/, /wp-includes/ and other necessary files.
  • Site address – It is the URL of your site, where people usually log on.

In most cases, both addresses remain the same. But in some cases, they may be different. If we want to keep WordPress separate and maybe we have non-WordPress modules in our site.


How to get the WordPress admin email within the WordPress theme?

To get the WordPress admin email within a WordPress theme, we’ll use the bloginfo(‘admin_email’); tag, this function will return the email address set under Settings > General > Email Address.


How to get the stylesheet URL of a WordPress theme?

By using get_stylesheet_directory_uri(); We can access the current theme’s stylesheet directory.


Where we should keep the stylesheet of a theme?

In WordPress theme development, By default WordPress consider style.css file as theme’s main stylesheet. So we should keep this file in theme’s root folder.

wp-content/themes/theme-name/style.css

However, we can add other stylesheets in a WordPress theme according to the theme’s design or requirements.


How to get the template directory URL in WordPress?

In WordPress, by using get_template_directory_uri(); tag can retrieves the template directory URL.


How to get the stylesheet directory URL in WordPress?

In WordPress, by using get_stylesheet_directory_uri(); tag can retrieves the stylesheet directory URL.


What is the difference between get_template_directory_uri(); and get_stylesheet_directory_uri(); in WordPress?.

Both do the same work however in some cases they are different :

  • get_template_directory_uri(): – Returns the theme directory URL, which points to the active theme folder.
  • get_stylesheet_directory_uri(): – Returns the stylesheet directory URL, which also points to the active theme folder. But if we are using a child theme, it will return with the child theme’s stylesheet directory URL.

How to link stylesheet in a WordPress theme?

Linking Stylesheets or CSS files in WordPress is quite easy. We can add any stylesheets in WordPress theme by linking them through ‘link’ HTML element.

Eg: <link rel="stylesheet" href="<?php get_template_directory_uri();?>/style.css" />

How to get the page title in a WordPress theme outside the loop?

To get and display the page title/post title outside the loop or any area of blog/website. We simply use the function

wp_title();

This function accepts 3 parameters and they are completely optional.

wp_title($sep, $display, $sep_location);

$sep – Separate the items in page title (By default use this ‘ >> ‘ , however we can use own separator like ‘ – ‘, ‘ | ‘, ‘ > ‘ etc).

$display – either should be displayed or not (It will be either True or False).

$sep_location – Separator location to display title. (It will be either left or right).


How to display Post or Page Title in a WordPress Theme inside the loop?

To get and display the post or page title inside the loop, we use the_title() tag.


How to get the link of a page or post in WordPress theme inside the loop?

To get the URL or link of a page or post inside the loop we use the_permalink();


How to get the excerpt of a page or post in WordPress theme?

To get the excerpt of a page in WordPress, we use the_excerpt(); tag.


What is the default length of excerpts?

Excerpts length is the number of words to display as the preview text for a post or page. By default excerpts length is ‘ 55 ‘, however, we can easily increase or decrease it based on our requirements.


How can we edit the excerpt length?

WordPress has a built-in filter excerpt_length that allow us to edit the length of the excerpts. To edit the length simply add this filter in your theme’s function.php file with the number of words you want to display in the excerpt.

add_filter(' excerpt_length ', function( $length ) { return 30 ; } );

How to display the post content in WordPress theme?

To display the post content, we simply use the_content(); tag. This tag allows us to retrieve post content’s data and display in the template.


How to display tags of a post in WordPress theme?

To display tags of a post, will use the_tags(); tag. By using this function, we can easily get all the tags associated with that particular post.


How to check if a post has tags or not?

To check the tags of a post, WordPress has another template tag. has_tag(); this allows us to check if a post has tags and return true and vice versa.


How to enable post thumbnail support or featured image option in WordPress Theme?

To enable post thumbnail support for a WordPress theme, we have to register theme support for post thumbnails by adding this into the functions.php file.

add_theme_support( ' post-thumbnails' );

How to display a thumbnail of the post in WordPress theme?

To display post thumbnail of a post, We use the_post_thumbnail(); tag.


How to check if a post has a thumbnail or not in a WordPress theme?

To check post thumbnail of a post, We use has_post_thumbnail(); tag.


How to display search form in a WordPress theme?

In WordPress, We have a function get_search_form(); By using this function we can display search form in WordPress theme.


How to get the login link in WordPress theme?

WordPress has a built-in function to get the login URL. wp_login_url(); This template tag returns the URL for login.


How to get the logout link in WordPress theme?

WordPress has a built-in function wp_logout_url(); this returns the url that allow users to logout.


How to get lost your password link in WordPress theme?

wp_lostpassword_url();, this function returns the URL that allow users to retrieve their password.


How to display comment form in WordPress theme?.

To display comment form in a WordPress theme, WordPress has a function comment_form();. This function displays the comment form.


How to display the link of category or categories of a post inside the loop?

To display the link of category(s), WordPress has the_category(); tag. This tag will return the link of category or categories. It should be used inside the loop.


How to get the navigation Menu in WordPress theme?

By using wp_nav_menu(); function we can display the navigation menu in a WordPress theme.


What is the difference between wp_title() and the_title() in WordPress.

wp_title() and the_title() both are used to display page or post title. Only the difference is:

  • wp_title() – works outside the loop.
  • the_title() – works inside the loop.

How to check if any post type exists or not?.

To check if any post exist or not we can use post_type_exists( $post_type ); where $post_type is the name of post types.


How to check current post has an excerpt?

To check excerpt of the current post, we can use has_excerpt(); function.


How to check if a user exists in WordPress database or not?

To check a user in WordPress database, We can use an in-built function

username_exists($username);

Where $username is required.

Example:

if(username_exists('admin')){
	echo 'username exists';
}

else{
echo 'username does not exists'; 
}

To Be Continued…!


Keep Visiting, I will add more questions soon.

Owner of diveinwp.com, solely responsible for creating helpful, informative content about WordPress, a fulltime WordPress developer with 8+ years of hands-on experience in WordPress design and development.