Thursday, 2 August 2018

Wordpress Interview Questions Answers



1. What is WordPress?
ans. WordPress is free open source content management system (CMS) written PHP language. It allows users to create dynamic websites from personal blogs to e-commerce.Wordpress current stable version 4.9.7 as on July @018.

2. What year was WordPress released?
ans. 2003

3. minimum requirements to run WordPress.
ans.  PHP version 7.2 or greater. MySQL version 5.6 or greater OR MariaDB version 10.0 or greater.

4. Where is WordPress content stored?
ans. MySQL database on Server.

5. differences between Posts and Pages?
ans. Posts and Pages are the two content types in WP.
     1.Posts are timed and listed in chronological order with the latest posts at the top. Posts are meant to be shared and commented on.
     2. Pages are static are static content, so an about us, contact us page etc. They are permanent and timeless entries.

6. types of hooks in WP.
ans. two types hooks are available in WordPress, action hooks and filter hooks, modify areas in a theme or plugin without modifying the original file.

7. action hook.
ans. An Action hook in WordPress is a hook that is triggered at a specific time when WordPress is running and lets you take an action. This can include things like creating a widget when WordPress is initializing or sending a Tweet when someone publishes a post.
list of some Action hooks functions.
        has_action()
        add_action()
        do_action()
        do_action_ref_array()
        did_action()
        remove_action()
        remove_all_actions()
        doing_action()

8. filter hook.
ans. A Filter hook in WordPress allows you get and modify WordPress data before it is sent to the database or the browser. Some examples of filters would include customizing how excerpts are displayed or adding some custom code to the end of a blog post or headings.
               
    example of add_filter
    add_filter('the_content', 'hello_world');
    function hello_world($content){
        return $content . "<h1> Hello World </h1>";
    }

      list of some Filter hooks functions.
        has_filter()
        add_filter()
        apply_filters()
        apply_filters_ref_array()
        current_filter()
        remove_filter()
        remove_all_filters()
        doing_filter()

9. WordPress taxonomy.
ans. In WordPress, a “taxonomy” is a grouping mechanism for some posts (or links or custom post types).There are four default taxonomies in WordPress they are
        Category
        Tag
        Link Category
        Post Formats
        You are also free to create your custom taxonomies too.
   
10. default tables are the WordPress. - WordPress Tables 12.
ans. wp_commentmeta, wp_comments, wp_links, wp_options, wp_postmeta, wp_posts, wp_terms, wp_termmeta, wp_term_relationships, wp_term_taxonomy, wp_usermeta, wp_users.

11. How to run database Query on WordPress?
ans. <?php $wpdb->query('query'); ?> , other wpdb functions above such as get_results, get_var, get_row or get_col.

12. General tags - general-template tags
ans. 
     A template tag is code that instructs WordPress to “do” or “get” something. Like in header.php  we will use the tag bloginfo(‘name’) to get “Site Title” from wp-options table which is set in Setting > General at WordPress dashboard.
   
    The the_title() template tag is used to display the post title.
   
    wp_list_cats() is  for display categories.
   
    get_header() for getting header.
   
    get_sidebar() for display the sidebar on page.
   
    get_footer() for get the footer content on page.
           
    get_template_part()
    get_search_form()
    wp_loginout()
    wp_logout_url()
    wp_login_url()
    wp_login_form()
    wp_lostpassword_url()
    wp_register()
    wp_meta()
    get_bloginfo()
    get_current_blog_id()
    wp_title()
    single_post_title()
    wp_enqueue_script()
    get_the_author()
    wp_list_authors()
    category_description()
   
13. Does WordPress use cookies?
ans. Yes, WordPress has cookies and uses them for verification purpose of the users while they log in.

14. Which is the considerably best multilingual plugin in WordPress?
ans. WPML is the best multilingual plugin for WordPress.

15. write the short code in WordPress php file?
ans. <?php do_shortcode("[shortcode]"); ?>

16. In which cases you don’t see plugin menu?
ans. You can’t see your plugin menu when the blog is hosted on free wordpress.com as you cannot add plugin there.  Also, if you do not have an account of an administrator level on your WordPress dashboard, it is not possible to see plugin.

17. difference between the wp_title and the_title tags?
ans. wp_title() function is for use outside “The Loop” to display the title of a Page.  the_title() on the other hand is used within “The Loop“.

18. How to Create Custom Post Type?
ans. // Our custom post type function
    function create_posttype() {    
        register_post_type( 'movies',
        // CPT Options
            array(
                'labels' => array(
                    'name' => __( 'Movies' ),
                    'singular_name' => __( 'Movie' )
                ),
                'public' => true,
                'has_archive' => true,
                'rewrite' => array('slug' => 'movies'),
            )
        );
    }
    // Hooking up our function to theme setup
    add_action( 'init', 'create_posttype' );
   
19. check if a page exists by url?
ans. You can use get_page_by_path() function.

20. create mailchimp or vertical response campaign for newsletter subscribers & link with WordPress ?
ans. First Create List & Campaign on mailchimp/ WordPress account . Then subscribe users from WordPress in mailchimp list by plugin or  manual hard code webform.

21. How will you retrieve adjacent posts (next/previous) within the same category?
ans. We can retrieve previous post using get_adjacent_post() function and providing it ‘true‘ and taxonomy name in first and last parameters respectively. Setting third parameter to false will bring next adjacent post in front of you.

22. Activate Plugins via Code?
ans.       
                function plugin_activation( $plugin ) {
        if( ! function_exists('activate_plugin') ) {
            require_once ABSPATH . 'wp-admin/includes/plugin.php';
        }   
        if( ! is_plugin_active( $plugin ) ) {
            activate_plugin( $plugin );
        }
    }   
    plugin_activation('akismet/akismet.php');
       
23. How to Link External jQuery/Javascript files with WordPress
ans. Add your own scripts via wp_enqueue_script() in your template’s functions.php, appropriately setting dependences on jQuery, and wp_head() will add the scripts for you.

24.  How to retrieve an image attachment’s alt text?
ans. The wp_get_attachment_image() function which will return an HTML string containing these attributes:
    ‘src‘
    ‘class‘
    ‘alt‘
    ‘title‘.

25. inner join query :
    SELECT Orders.OrderID, Customers.CustomerName FROM Orders
    INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;

26. SQL GROUP BY query :
                SELECT COUNT(CustomerID), Country FROM Customers
    GROUP BY Country ORDER BY COUNT(CustomerID) DESC;

27. wordpress plugins : conatc form 7, meta slider, ninja form, revolution slider, yost seo, buddypress, wp super cache, wordfance.

28. get sidebar by id name : <?php dynamic_sidebar( 'left-sidebar' ); ?>

29. Add a WordPress Widget :
ans.
    function wpb_widgets_init() {    
        register_sidebar( array(
            'name'          => 'Custom Header Widget Area',
            'id'            => 'custom-header-widget',
            'before_widget' => '<div class="chw-widget">',
            'after_widget'  => '</div>',
            'before_title'  => '<h2 class="chw-title">',
            'after_title'   => '</h2>',
        ) );    
    }
    add_action( 'widgets_init', 'wpb_widgets_init' );

-------------------------------------------------
Let me know your thoughts and questions in the comments.
Email: vyasankit2008@gmail.com

No comments:

Post a Comment