Freshers WordPress Interview Questions

What is the difference between categories and tags in WordPress?

Categories group posts by main topic. They can have parent and child categories, and every post must have at least one (the default is Uncategorized).

Tags describe small details of one post. They have no hierarchy and a post can have no tags.

A simple example for a cooking blog: categories are Breakfast, Lunch and Dinner; tags are quick, vegan and spicy.

Terminal output

$ wp taxonomy list –object_type=post –fields=name,label,hierarchical
name label hierarchical
category Categories 1
post_tag Tags
post_format Formats

Both are taxonomies. Read Categories and Tags.

How to install WordPress?

The classic way is the famous 5 minute install:

  1. Download WordPress from wordpress.org and unzip it.
  2. Put the files in the web folder of your server (public_html or htdocs).
  3. Create an empty MySQL or MariaDB database and a user.
  4. Open the site address in the browser, and enter the database details.
  5. Enter the site title, admin username, password and email.
  6. Click Install WordPress and log in at /wp-admin.

With WP-CLI, the same install needs four commands:

wp core download
wp config create --dbname=mysite --dbuser=root --dbpass=secret
wp db create
wp core install --url=http://localhost --title="My Site" --admin_user=admin --admin_password=Strong#Pass1 --admin_email=you@example.com

Details are in WordPress Installation. Always use a strong admin password.

What is the WordPress Loop?

The Loop is the code which WordPress uses to show posts in a template. It checks if there are posts, goes through them one by one, and prints the post data with template tags.

<?php if ( have_posts() ) : ?>
	<?php while ( have_posts() ) : the_post(); ?>
		<h2><?php the_title(); ?></h2>
		<?php the_excerpt(); ?>
	<?php endwhile; ?>
<?php else : ?>
	<p>No posts found.</p>
<?php endif; ?>
  • have_posts(): are there posts left?
  • the_post(): move to the next post and set up its data.
  • the_title(), the_content(): print the details of the current post.

See The WordPress Loop for a tested example and WP_Query for custom loops.

What are widgets in WordPress?

A widget is a small piece of content or a feature, like a search box, a list of recent posts, a calendar or a text box. You place widgets in widget areas (also called sidebars) of the theme, for example the sidebar or the footer.

Since WordPress 5.8 the widget screen works with blocks, so any block can be a widget. Block themes do not have widget areas, they use template parts and the Site Editor.

Developers create new areas with register_sidebar() and print them with dynamic_sidebar(). See Widgets and Register Sidebar.

What are permalinks in WordPress? Which structure is the best?

A permalink is the permanent URL of a post, page or archive. You choose the structure in Settings > Permalinks.

Terminal output

$ wp rewrite structure '/%postname%/'
Success: Rewrite structure set.
Success: Rewrite rules flushed.
$ wp eval 'echo get_permalink(1);'
http://example.com/hello-world/

The options are Plain (/?p=123), Day and name, Month and name, Numeric, Post name and Custom. For most sites Post name is best, because the URL is short and readable, and has the keyword.

If new pages show a 404 error after a change or a move, save the permalink settings again to refresh the rewrite rules. More in Permalinks.

What is Gutenberg in WordPress?

Gutenberg is the name of the block editor, which became the default editor in WordPress 5.0 (December 2018). Instead of one big text box, each part of the content is a block: paragraph, heading, image, list, table, button and so on.

A block is saved as normal HTML with a comment around it:

Terminal output

$ wp post create –post_title="Block demo" –post_content='<!– wp:paragraph –><p>Hello block</p><!– /wp:paragraph –>' –post_status=draft –porcelain
5
$ wp post get 5 –field=post_content
<!– wp:paragraph –><p>Hello block</p><!– /wp:paragraph –>

Gutenberg is also used for the Site Editor of block themes. Read WordPress Block Editor.

What is a shortcode in WordPress?

A shortcode is a small tag inside square brackets which WordPress replaces with some output when the page is shown. For example shows an image gallery.

To make your own, use add_shortcode(). The function must return the text (not echo it):

add_shortcode( 'hello', function ( $atts ) {
	$a = shortcode_atts( array( 'name' => 'friend' ), $atts );
	return 'Hello, ' . esc_html( $a['name'] ) . '!';
} );
echo do_shortcode( '[hello name="Riya"]' );
Output

Hello, Riya!

See Shortcode API.

What is the difference between is_home() and is_front_page()?

is_front_page() checks the front page of the site: it can be the latest posts page or a static page, as set in Settings > Reading.

is_home() checks the blog posts page, where the latest posts are listed.

Reading settingis_front_page()is_home()
Your latest poststrue on the home pagetrue on the home page
A static page for the front, and another for the poststrue on the static front pagetrue on the posts page only

So when you show the latest posts on the front, both are true. After you set a static front page, they are different. See Conditional Tags.

How to reset a WordPress admin password?

There are three ways:

  1. Lost your password link: on the login page click Lost your password?, enter your username or email, and open the reset link from the email.
  2. WP-CLI: change it from the command line (good when email does not work).
  3. phpMyAdmin: edit the user_pass field of the user in wp_users and choose the function MD5 for the new password. WordPress will upgrade the hash on the next login.
Terminal output

$ wp user list –fields=ID,user_login,user_email
ID user_login user_email
1 admin admin@example.com
$ wp user update admin –user_pass="NewStrongPass#2026" –skip-email
Success: Updated user 1.

Note: Use a long password and a password manager. See WordPress Security.

How to enable debugging in WordPress?

Add these lines in wp-config.php (above the line “That’s all, stop editing”):

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );       // save errors in wp-content/debug.log
define( 'WP_DEBUG_DISPLAY', false );  // do not show errors on the page

You can set them with WP-CLI, too:

Terminal output

$ wp config set WP_DEBUG true –raw
Success: Added the constant 'WP_DEBUG' to the 'wp-config.php' file with the raw value 'true'.
$ wp config get WP_DEBUG
1
$ wp config delete WP_DEBUG
Success: Deleted the constant 'WP_DEBUG' from the 'wp-config.php' file.

Turn debugging off on a live site. Learn more in WordPress Debugging.

What is the wp-config.php file?

wp-config.php sits in the root folder of the site. It holds:

  • The database name, user, password and host (DB_NAME, DB_USER, DB_PASSWORD, DB_HOST).
  • The security keys and salts.
  • The table prefix ($table_prefix).
  • Options like WP_DEBUG, WP_MEMORY_LIMIT and DISALLOW_FILE_EDIT.

It is created during the install from wp-config-sample.php. Keep it private and back it up. See The wp-config.php File.

What is a child theme in WordPress and why use it?

A child theme uses another theme (the parent) as its base. It needs a style.css with a Template: line (the parent folder name) and usually a functions.php.

/*
Theme Name: My Child Theme
Template: twentytwentyone
*/

Any file you copy to the child with the same name replaces the parent file. The rest comes from the parent. The main reason to use it: when the parent theme is updated, your changes stay safe. See WordPress Child Theme.