Interview Questions for Experienced WordPress Developers

#1. 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.


#2. 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.


#3. 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.


#4. 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.


#5. 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.


#6. 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.


#7. 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.


#8. 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.


#9. 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.


#10. How to get the template directory URL in WordPress?

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


#11. How to get the stylesheet directory URL in WordPress?

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


#12. 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 child theme’s stylesheet directory URL.


#13. 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" />

#14. 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).


#15. 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.


#16. 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();


#17. 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.


#18. 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.


#19. 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 ; } );

#20. 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.


#21. 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.


#22. 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.


#23. 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' );

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

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


#25. 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.


#26. 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.


#27. 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.


#28. 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.


#29. 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.


#30. 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.


#31. 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.


#32. 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.


#33. 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.


#34. 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.


#35. How to check current post has an excerpt?

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


#36. 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, Will add more questions soon. If you guys have any questions please put them in the comment box to list.

And if you guys think there is something wrong info for any questions and answers and should be correct, feel free to share.

I would highly appreciate your feedback.

Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top