Interview FAQ WP Interview FAQ
This article will cover all the relevant wordpress questions with answers that are frequently asked in an interview for theme development, theme designing.
What is theme?
A WordPress Theme is a collection of template and style sheets. In WordPress Dashboard WordPress themes are in Appearance–> Themes . You can change any theme from here.
How to create a custom theme in WordPress?
Create a theme folder in /wp-content/themes/ folder
/wp-content/themes/custom-theme
Create index.php and style.css file in custom-theme folder. In style.css write
<?php /* Theme Name: My Custom theme Theme URI: https://curiouswebs.in/ Author: curiouswebs Author URI: https://curiouswebs.in/ Description: Well Responsive HTML 5 Custom theme License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Text Domain: twentyseventeen Tags: one-column, two-columns, right-sidebar, flexible-header, accessibility-ready, custom-colors, custom-header, custom-menu, custom-logo, editor-style, featured-images, footer-widgets, post-formats, rtl-language-support, sticky-post, theme-options, threaded-comments, translation-ready This theme, like WordPress, is licensed under the GPL.*/
Now theme is ready to install via Appearance > Themes > Custom theme > just activate it.
What is basic WordPress theme structure?
A basic WordPress theme has following files
index.php : main template file
style.css : For styling theme
header.php : header content
footer.php : footer content
page.php : template for wordpress pages
front-page.php : template for home page or front page
singular.php : template for post details page. If it is not found page.php is used. if page.php is not found index.php is used.
single.php : template for post details page
single-{post-type}.php : template for specific post type detail page.
archieve-{post-type}.php : template for listing of all the posts
page-{slug}.php : template for specific page
category.php : template for category
tag.php : template for tags
taxonomy.php : template for custom taoxnomies
author.php : template for author pages
search.php : template used for search results
404.php : template used for when page is not found.
date.php : template used for post details when url is date wise.
comments.php : template for comments.
Name some theme functions to include theme files?
get_header() : To include header file in a template
get_footer(): To include footer file in a template
get_sidebar(): To include sidebar in a template.
get_search_form(): To include search form
get_template_part() : To include a template part in theme
How to create menu in theme?
Using wp_nav_menu() function. Parameters passed to this function are menu name, title,location,menu wrapper id or class etc.
Basic Syntax is
<?php wp_nav_menu( array $args = array( 'menu' => "", // (int|string|WP_Term) Desired menu. Accepts a menu ID, slug, name, or object. 'menu_class' => "", // (string) CSS class to use for the ul element which forms the menu. Default 'menu'. 'menu_id' => "", // (string) The ID that is applied to the ul element which forms the menu. Default is the menu slug, incremented. 'container' => "", // (string) Whether to wrap the ul, and what to wrap it with. Default 'div'. 'container_class' => "", // (string) Class that is applied to the container. Default 'menu-{menu slug}-container'. 'container_id' => "", // (string) The ID that is applied to the container. 'fallback_cb' => "", // (callable|bool) If the menu doesn't exists, a callback function will fire. Default is 'wp_page_menu'. Set to false for no fallback. 'before' => "", // (string) Text before the link markup. 'after' => "", // (string) Text after the link markup. 'link_before' => "", // (string) Text before the link text. 'link_after' => "", // (string) Text after the link text. 'echo' => "", // (bool) Whether to echo the menu or return it. Default true. 'depth' => "", // (int) How many levels of the hierarchy are to be included. 0 means all. Default 0. 'walker' => "", // (object) Instance of a custom walker class. 'theme_location' => "", // (string) Theme location to be used. Must be registered with register_nav_menu() in order to be selectable by the user. 'items_wrap' => "", // (string) How the list items should be wrapped. Default is a ul with an id and class. Uses printf() format with numbered placeholders. 'item_spacing' => "", // (string) Whether to preserve whitespace within the menu's HTML. Accepts 'preserve' or 'discard'. Default 'preserve'. ) );
For more information check this link.
How to create different menu for logged in or logged out user?
<?php wp_nav_menu( array( 'theme_location' => is_user_logged_in() ? 'logged-in-menu' : 'logged-out-menu' ) );
How to create widget area or sidebar in theme?
register_sidebar() function is used to create a sidebar . There are basically two steps to create it.
Step 1: Register a custom sidebar widget area
<?php function curious_webs_widget() { register_sidebar( array( 'name' => __( 'Blog Page Sidebar', 'curiouswebs' ), 'id' => 'blog-page-sidebar', 'before_widget' => '<div class="blog-page-sidebar">', 'after_widget' => '</div>', 'before_title' => '<h1 class="widget-title">', 'after_title' => '</h1>', ) ); } add_action( 'widgets_init', 'curious_webs_widget' );
Step 2: Call this widget in theme wherever required.
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Blog Page Sidebar") ) : ?> <?php endif;?>
How to create user role?
using add_role() function.
Basic Syntax is:
<?php add_role( $role, $display_name, $capabilities ); ?>
<?php add_role( 'guest_author', __( 'Guest Author', 'testdomain' ), array( 'read' => true, // true allows this capability 'edit_posts' => true, 'delete_posts' => false, // Use false to explicitly deny ) );
For More information check here.
Name different user role function?
add_role(): To add a role
remove_role() : to remove a role
add_cap(): to add capabilities to a role
remove_cap(): remove capabilities from a role
get_role(): get information about the role like name and capabilities.
What is custom post type?
A custom post type is a post type but have different value in database instead of default post. It can be created by using register_post_type function.
function custom_post_type_book() { $args = array(); register_post_type( 'book', $args ); } add_action( 'init', 'custom_post_type_book' );
What is custom taxonomy?
They are used to group post together. By default wordpress has category taxonomy. However custom taxonomy can be created by using register_taxonomy function.
<?php add_action( 'init', 'create_book_tax' ); function create_book_tax() { register_taxonomy( 'book_tax', //taxonomy name 'book' // post type name array( 'label' => __( 'Book Categories' ), 'rewrite' => array( 'slug' => 'book_tax' ), 'hierarchical' => true, ) ); } ?>
What is tag?
It is WordPress default taxonomy. They are basically used as keywords for a post.
What is the difference between tag and category?
Both are used to group posts but the difference is if the classification has some hierarchy category is used. If there is no hierarchy then tag is used. For example book categories can be Fiction -> Science Fiction -> Historical Fiction etc. and book tag can be most popular , editor choice etc.
What is child theme?
Any custom styling or functionaliy will be lost when a theme is updated. So child theme will be created by inheriting the parent theme.So child theme allow user to add , modify parent theme functionalities without losing the ability to update its parent theme.
How to create a child theme?
- create child theme folder in /wp-content/themes/default-child
- create a style sheet in this folder and add following code into
/*
Theme Name:
Dummy Theme ChildTheme URI: http://
curiouswebs.in/parent-theme-name-urlDescription: Dummy Child Theme
Author: A
B CAuthor URI: http://example.com
Template: dummy-theme
Version: 1.0.0
*/
how to override parent theme files?
Just copy parent theme’s file into child theme file and make changes to that file.
Name some form plugins
- contact form 7
- gravity form
- WP forms
- Ninja Forms
- Formidable forms
How to redirect a link in wordpress?
By using wp_redirect method.
function
my_logged_in_redirect() {
if
( is_page( 11 ) )
{
wp_redirect( get_permalink( 10 ) );
die;
}
}
add_action( 'template_redirect', 'my_logged_in_redirect'
);
How to include parent theme style into child theme style.
<?phpadd_action( 'wp_enqueue_scripts', 'dummy_child_theme_enqueue_styles'
);
function
dummy_child_theme_enqueue_styles
() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css'
);
}
So, these are some wp custom theme related questions that are asked frequently in an interview. If you find this article useful please share your feedback. Also you can tell other questions that you have faced in an interview for WP theme.