WordPress Interview Questions & Answers

Here, you will find Top WordPress Interview Questions and Answers.

These WordPress interview questions are helpful for freshers (beginners) as well as experienced job seekers.

Find, WordPress interview questions are related to WordPress CMS, functions, admin panel, file structure, database, themes, plugins, actions, filters along with examples.

What is WordPress?

WordPress is web software you can use to create a beautiful website or blog. We like to say that WordPress is both free and priceless at the same time.

Source: https://wordpress.org/

WordPress is an Open Source project, which means there are hundreds of people all over the world working on it. (More than most commercial platforms.) It also means you are free to use it for anything from your recipe site to a Fortune 500 web site without paying anyone a license fee and a number of other important freedoms.

In what year did WordPress come out?

WordPress is a free CMS (Content Management System) came in 2003.

How many default tables in WordPress database?

There are 12 default database tables in WordPress database as given below:

  • wp_options
  • wp_users
  • wp_links
  • wp_commentmeta
  • wp_term_relationships
  • wp_postmeta
  • wp_posts
  • wp_term_taxonomy
  • wp_usermeta
  • Wp_terms
  • wp_termsmeta
  • wp_comments
Note: Note: “wp_” is the default prefix but you can change it with another name.

Where is the WordPress content stored?

WordPress content is stored in the MySQL database on the Server.

What is default table prefix for WordPress database?

wp_ is the default table prefix for the WordPress database. Therefore, WordPress tables will look like ‘wp_posts’, ‘wp_users’ if you keep using default prefix.

See the list of WordPress Database Tables.

What are the Popular plugins in WordPress for SEO?

Here are the most popular SEO plugins for WordPress.

  • Yoast SEO
  • All in One SEO Packs
  • The SEO Framework

What is a WordPress theme?

A WordPress theme is a group of files that defines the design of a WordPress website.

WordPress theme folder contains PHP (with HTML), CSS, JavaScript, and other kinds of files creates look and feel of the WordPress site. WordPress themes are kind of independent folders that can be installed and activated in any WordPress site.

What are commonly used WordPress theme functions?

There are many built-in WordPress functions that we use in theme customization. Here are some of the mostly used WordPress theme functions:

  • get_template_directory_uri() – Retrieve template directory URI for the current theme. In the event that a child theme is being used, the parent theme directory URI will be returned. Use get_stylesheet_directory_uri() to include resources that are intended to be included in/overridden by the child theme.
  • wp_head() – The wp_head action hook is triggered within the & section. You use this hook by having your function echo output to the browser in HTML head. Most of default actions into the ‘wp-head’ hook by WordPress core. You might use it to include your own js/css and other meta into the WordPress.
  • wp_nav_menu() – Displays a navigation menu created in the Appearance → Menus panel. For example: ‘Project Nav’ )); ?>
  • home_url()– The home_url template tag retrieves the home URL for the current site
  • e_()- Displays the returned translated text from translate()
  • get_sidebar() – Includes the sidebar.php template file from your current theme’s directory.
  • get_header()– Includes the header.php template file from your current theme’s directory.
  • wp_link_pages()– Displays page-links for paginated posts (Next page & Previous Page)
  • edit_post_link()– display link to edit current post from dashboard

Describe WordPress files and directory structure

Here is the list of important WordPress files & directory structure:

WordPress Root/

  • wp-admin/
    • css/
    • images/
    • other core PHP files…
  • wp-content/
    • plugins
    • themes
    • uploads
    • upgrade
  • wp-includes/
    • css/
    • images/
    • other core PHP files…
  • .htaccess
  • wp-config.php
  • wp-blog-header.php
  • other core PHP files

How to limit WordPress Post content length?

Sometimes, we only want to show initial WordPress post content on the site. There are many ways to limit the WordPress post content length. One way is to replace WordPress the_content() in WordPress template files with following code.

<?php
$article_data = substr(get_the_content(), 0, 300);
echo $article_data;
?>

Explanation

get_the_content() function contains wordpress content page/post content. Then it will pass it to php substr() function to limit the content to 300 characters. Then you can display wherever you want.

Which function is used to get home URL in WordPress?

get_home_url(); and home_url(); functions is used to get home url in WordPress.

// Example to get home url
$url = home_url();
echo $url;
// Output: https://example.com

// Example to get url of any page using slug
$url = home_url().'/about';
echo $url;
// Output: https://example.com/about

Which are the necessary files for WordPress Theme?

The necessary files for WordPress theme are two for proper functioning:

index.php

  1. index.php
  2. style.css

These two files are minimum required files for proper working of WordPress theme.

As you can imagine, the first file index.php” deals with providing the contents to display while the second one “style.css” is used to establish the method through which these contents will be shown on the screen. WordPress first check "style.css" to identify the theme name & other information.

What is WordPress default feed cache recreation time? How to change it?

Default feed cache recreation time:
By default, WordPress feed cache recreation time or rather the cached feed has a lifetime of 43200 seconds, equivalent to 12 hours.

How to change it using the WordPress filter:
Change the default feed cache recreation period to 1800 seconds/30 minutes using wp_feed_cache_transient_lifetime filter

<?php
function return_cache_recreation( $seconds )
{
  return 1800;
}
add_filter( 'wp_feed_cache_transient_lifetime' , 'return_cache_recreation' );
/* Ends: Change the default feed cache recreation period */
?>

How to create A WordPress Global Options Page?

Thea dd_options_page() function adds sub menu page to the Settings menu.

Add Options Page Syntax

<?php
add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function);
?>

Example of Options Page creation

add_action('admin_menu', 'my_plugin_menu');
function my_plugin_menu() {
	add_options_page('My Options', 'My Plugin', 'manage_options', 'my-plugin.php', 'my_plugin_page');
}

WordPress Codex Reference: https://codex.wordpress.org/Function_Reference/add_options_page

How to create WordPress plugin from scratch?

How do WordPress plugins work?

A WordPress Plugin is a set of one or more functions, that specifies set of features at certain points using Plugin APIs Hooks.
Hooks allow your plugin to call functions at specific times to alter or enhance the existing functionality.


There are two kinds of hooks

  • Actions: In WordPress; an Action is a PHP function that is executed at specific points throughout the WordPress Core. For example: A developer may want to add code to the footer of a Theme. This could be accomplished by writing new function, then Hooking it to the wp_footer Action
  • Filters: In WordPress, a Filter is a function that is associated with an existing Action by specifying any existing Hook. Filters usually come with content already associated with them. They allow you to add or remove code from existing Actions.

Creating the Plugin folder with unique name

In this folder, we will create two files:

  • readme.txt
  • wp-plugin-name.php

The readme file is required if you want to host your plugin on the WordPress.org Plugin Directory.


File Headers

Now it’s time to put some information into your main Plugin PHP file. At a minimum, a header can contain just a Plugin Name, but several pieces should be included:

It is recommended that you prevent direct access to this file by including this line after your file headers:


Enqueueing JavaScript and CSS files

Make data available to JavaScript

Now we have some settings stored, we need to make them available to the JavaScript. “wp localize script” can be used to make any data available to your script that you can normally only get from the server-side of WordPress.

Activation and Deactivation hooks

register_activation_hook and register_deactivation_hook, run their callbacks on activation and deactivation of the plugin and perform the required functionality like adding or erasing the plugin’s metadata.

Full Example: https://gist.github.com/deepak-rajpal/f8fb397d16bb161b3ba1

Why Do We Use Activation/Deactivation Hooks

We can create basic plugins without considering activation and deactivation functions. But advanced plugin will require these functions to provide additional features:

  • Create custom database tables on activation to store data and remove tables on deactivation.
  • Create custom options for plugins and activation and reset in deactivation.
  • Validate other dependent plugins on activation.
  • Any other necessary task you need to execute inactivation.

How to increase maximum execution time in PHP and WordPress

We mostly see that the maximum execution time of a PHP Script is 30 seconds. If a script takes more than 30 seconds to execute, it will throw the following Fatal error.
Fatal error: Maximum execution time of 30 seconds exceeded in ….

We can increase maximum execution time in PHP and WordPress by using various methods. In the following examples, we have increased maximum execution time to 360 seconds (6 minutes).


Method 1: By adding the code in a PHP file:

We can set the maximum execution time by adding this code in a PHP File. You must add this code in that file which is included earlier in all other pages. Then this function will increase maximum execution time in all those files.
For example, put this code in the header (header.php), or configuration (config.php) if available.
set_time_limit(360);


Method 2: Inside the .htaccess file:

We can do the same thing inside the .htaccess file as well. Before editing this file, you make sure to have a backup of .htaccess.
php_value max_execution_time 360


Method 3: Inside the php.ini file:

We can also set the maximum execution time by adding this code in the php.ini file.
max_execution_time = 360


Method 4: Inside wp-config.php file in WordPress:

If you are using WordPress then you can place this code in wp-config.php file.
set_time_limit(360);


Note: Note: These methods will only work if you are allowed to change PHP configuration by your Hosting Server.

What Menu position and order available in WordPress?

WordPress ‘menu_position’ or ‘position’ parameter is used to set menu position inside the Dashboard. This parameter used in register post type(), add_menu_page() and other WordPress functions.


List of Menu positions available in WordPress:

  • 5 – below Posts
  • 10 – below Media
  • 15 – below Links
  • 20 – below Pages
  • 25 – below comments
  • 60 – below first separator
  • 65 – below Plugins
  • 70 – below Users
  • 75 – below Tools
  • 80 – below Settings
  • 100 – below second separator

What is the difference between Posts & Pages in WordPress?

There are two common types of the content section in WordPress: Posts and Pages. Here we will read about the difference between these two content.

Difference between Posts and Pages in WordPress

S.NOPostsPages
1Posts have categories and tags The content in a post is published under a category or a tag. At least one category is mandatory but tags are optional in WordPress Posts.No categories and tags WordPress Pages can have a parent child relationship but do not have categories and tags.
2Created frequently Posts can be added or created frequently.Not created frequently Pages are static content which doesn’t need to be added or created frequently.
3Comments WordPress Posts usually have the commenting feature enabled.Comments WordPress Pages can have comments but the feature is usually disabled and are not generally used.
4RSS feed available Posts are displayed in RSS field.RSS feed unavailable Pages are not displayed in RSS field.
5Examples News, blog articles, tutorials, etc all come under WordPress posts.Examples About, Contact, etc all come under WordPress pages because once created, the content doesn’t need to be changed frequently.
6Custom Formats Posts have custom formats of different types. These type of formatting is dependent on content type like image, video, quote, gallery, etc.Custom Formats Pages rarely have custom formats and if they have only templates are available.

What are the different user roles in WordPress?

WordPress user roles define what actions each user can perform on your website.

WordPress provides 6 pre-defined roles that site owner can set for each user.

  • Super Admin – This user has access to the site network administration features and all other features. User can install a new site, install themes, install plugins, add other users, create and edit any post or pages, and change all settings related to WordPress website. This user role is only available in WordPress Multisite Network.
  • Administrator  – This user can perform all the administration features within a single site. User can install themes, install plugins, add other users, create and edit any post or pages, and change all site settings.
  • Editor  – User with editor role can create and edit his posts and pages as well as of other users.
  • Author – This user can create and edit their own posts only.
  • Contributor – This user who can create and manage their own posts but cannot publish them. Only Higher level user can approve and publish contributor’s content.
  • Subscriber – This user can only manage their profile information. This role is helpful when you want to add users for Newsletter subscriber.

Additionally, you can add Custom User Roles via coding or plugin based on your requirement.

Which Gutenberg Blocks support Wide width and Full width alignment?

WordPress Gutenberg editor supports two width alignment options: Wide width and Full width.

Wide width: This option is used to align component on fixed or limited width (Somewhat similar to Bootstrap .container class).

Full width: This option is used to align component on full width (Somewhat similar to Bootstrap .container-fluid class).

There are following Gutenberg blocks that support these alignment width options.

  • Group Block
  • Cover Image Block
  • Image Block
  • Gallery Block
  • Pullquote Block
  • Video Block
  • Table Block
  • Columns Block
  • Embed Block

Note: These will work only if your theme supports. Also, this alignment options are useful for one column or full width page design as compared to page with sidebar.