Category Archives: WordPress

Articles and Interview Questions,Tips related to Wordpress – Interview Sortout

WordPress Organization Chart Plugin

An organisation is made-up of  Persons designated to various roles. There is hierarchy of Designation in each organisation.  Most of the roles has to report to the next level designated person.  If you have a website build on WordPress and you want to display the Chart of Organisation Structure  you need a WordPress Organisation Chart Plugin. There are many such plugins published on www.wordpress.org plugin repository.

Here we have listed many Plugins that you can use to display Organisation Graph:

Simple Org Chart

This plugin allows you to seamlessly setup a hierarchical based organisation chart, otherwise known as an Org Chart, for use in your website. We have integrated drag and drop features to ensure the process is intuitive and fast. This is an organizational chart maker. It provide you control to create custom post type and create structure of Organization.

DEMO

Main Features of WordPress Organization Chart Plugin

  1. Responsive
  2. Buddypress Support
  3. Multiple Charts
  4. JSON Access
  5. Custom Departments
  6. Simple user management
  7. Template system for custom design
  8. Hooks and Filters for custom fields
  9. Print Chart
  10. Replace Top Level user without reset chart

How to Install WordPress Organization Chart Plugin

  1. Upload file: “plugin-name.php” to the /wp-content/plugins/ directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress
  3. Settings -> Org Chart. Select Top Level user and press reset.
  4. Drag and Drop the users to arrange your chart as required. Press ‘Save Changes’ when you are ready.
  5. For New users there is drop down at bottom of chart page when they can be easily added.
  6. Use shortcode: [orgchart], in any page or post to display your chart.

Simple Org Chart

 

Spread the love

WordPress After Login Redirect Hook

Want to enhance your WordPress functionality using custom coding, then you are at the right place.  In this article, you are going to learn how to redirect on a custom page after a successful login in WordPress. When you are working on Woocommerce or any other type of application based on WordPress and you need to redirect your logged in user other than the default page or My Account page then you need to add few lines of codes in your functions.php.  Although there are many plugins available for this simple work you can create your own plugin using this successful login redirect code. WordPress is known for its simplicity and flexibility. We will use the feature of filters and hooks to extend the functionality.

Use hook wp_login()

There is wp_login() and we can use this function as a hook to create our own function and to redirect after login.

do_action( 'wp_login', string $user_login, WP_User $user )

 

Now we can write our own function to modify the default redirection. Suppose we have to redirect on the home page rather than the default page after successful login in WordPress. Then the code in the following example is sufficient :

function my_login_redirect() {
       wp_redirect(home_url());
        exit;
}
add_action( 'wp_login', 'my_login_redirect', 10, 3 );

 

Spread the love

How to add additional fields to user profile in WordPress

WordPress is the most-popular CMS and provides unlimited flexibility to users to do anything they wish.

To maintain its flexibility and maintainability WordPress provides hooks. Using these hooks we can extend the functionality and customize the interfaces as per requirement.

WordPress provides metadata to add additional information with content.

Using these meta we can add number of custom fields with any content like post, page,media,user,category,terms etc.

Here we would know that how to add an additional field to user profile?
For example we have to add highest educational qualification of users.

So we need to to add a user meta for this field. Let the field name is highest_qualification.

We will hook the user meta to the hooks related to user profile. Available hooks for user profile are:

  1. show_user_profile
  2. edit_user_profile
  3. personal_options_update
  4. edit_user_profile_update

These hooks enable user to add and update the meta field. Lets have a look on code snippets:
STEP #1: Add form field when user is going to edit the profile details:

Create a function add_user_educational_qualification and hook it with show_user_profile and edit_user_profile.

<?php
    add_action( 'show_user_profile', 'add_user_educational_qualification' );
    add_action( 'edit_user_profile', 'add_user_educational_qualification' );
    function add_user_educational_qualification( $user ) { ?>
	    
    <table class="form-table">
     <tr>
      <th>
       <label for="address"><?php _e("Highest Educational Qualification");?></label>
     </th>
     <td>
      <input type="text" name="highest_qualification" id="highest_qualification" value="<?php echo esc_attr( get_the_author_meta( 'highest_qualification', $user->ID ) ); ?>" class="regular-text" />
     <span class="description"><?php _e("Please enter your heighest Educational Qualification."); ?></span>
    </td>
 </tr>
</table>
<?php }  ?>

STEP #2 : Now we need to save this information to user_meta table , so we need the hook that are used to save or update the user profile and details.

Create a function save_user_educational_qualification and hook it with personal_options_update and edit_user_profile_update.


	add_action( 'personal_options_update', 'save_user_educational_qualification' );
	add_action( 'edit_user_profile_update', 'save_user_educational_qualification' );

	function save_user_educational_qualification( $user_id ) {
	    if ( !current_user_can( 'edit_user', $user_id ) ) { 
	        return false; 
	    }
	    update_user_meta( $user_id, 'highest_qualification', $_POST['highest_qualification'] );
	}

STEP #3: Now we need to display this information any where in the website:

We are ready with our additional field highest_qualification. We have added it and saved it to database.

WordPress provide a function highest_qualification and using this function we can get the value of meta fields.

 


<?php 
   $meta_key = 'highest_qualification'; 
   $highest_qualification = get_user_meta( $user_id, $meta_key,true); 
?>
Spread the love

How to create a custom page template in WordPress?

What is WordPress Template?

WordPress Page Template is a simple PHP script embedded in HTML page where we can design the layout and put the contents as per our requirement.

There are two parts of a page template

  1. Header
  2. Body

Header is the information part and for WordPress use. WordPress recognize these information in Header. And decide whether it is a page template or not.

<?php
/**
* Template Name: Interview Sortout Custom Page
* Template Post Type: post, page
* @package WordPress
* @subpackage Twenty_Fourteen
* @since Twenty Fourteen 1.0
*/

Template Name – A template is named as {my template name}. This option will be reflect in Layout option when we will create a Page or Post. Template name is not

Template Post Type – This is the scope of template , that where can we use this template. We have to specify that what post type can use this template.

Body is the main content representation. It organize the heading, Thumb images, content, breadcrumb, sidebar etc.


<?php get_header();?>
<div class="container">
	<h2 class="blog-title"><?php the_title(); ?></h2>
	<main><?php the_content();?></main>
	<aside><?php dynamic_sidebar('right-side-bar' ); ?></aside>
</div>
<?php get_footer();?>

 

A complete Page Template:

 


<?php
/**
* Template Name: Interview Sortout Custom Page
* Template Post Type: post, page
* @package WordPress
* @subpackage Twenty_Fourteen
* @since Twenty Fourteen 1.0
*/
get_header();?>
<div class="container">
	<h2 class="blog-title"><?php the_title(); ?></h2>
	<main><?php the_content();?></main>
	<aside><?php dynamic_sidebar('right-side-bar' ); ?></aside>
</div>
<?php get_footer();?>
Spread the love

WordPress Dashboard – Tutorial 4

Admin Login
  • Give the user name and password .
  • Check the remember box as the browser will remind the login and password next time.
Dashboard area contains the following main tools and links:
  • Welcome section
  • Main menu(side menu)
  • Top menu
  • Admin area
  • Screen option
  • Help option
  • Quick draft section
  • At a glance section
  • Activity section
 
Welcome Section
  • This section has some important links which used frequently.
  • We can customize our site look as we click on Customize Your Site button.
  • Direct links to add an about page, to write the first blog.
  • We can turn on/turn off comments by external user on our posts from here.
  • We can visit our menu and widget systems from the link given.
Screen Options:
  • Screen option shows a group of check boxes.
  • Each check box is for a particular section.
  • If it is checked the section is on the screen on the dashboard .
  • Unchecked boxes hide the section from dashboard.
  • Ex – we have to hide the Welcome section from screen. We will uncheck it.

Spread the love

WordPress Installation : Tutorial 3

WordPress Installation
Before install a WordPress we should ensure that we have already created a database , where we have to create the WordPress tables with a prefix name .Default is prefix is wp_. We should have the following information as we are going to install the WordPress:
  • Database Name: wordpress
  • User name: root
  • Password: by default blank
  • Hostname:localhost

Steps:

  1. Put
    the database name as you have created in the database field. It
    appears “wordpress
    by default.
  2. Give
    the mysql user name, which is root
    by default.
  3. Give
    the password of mysql , if you have’n define , then let the
    password field blank.
  4. Give
    the host name as running on default port, localhost.
  5. Give
    a prefix for the table name , which are being install in database.

A wp-config.php file is created, containing the information about database, username, password etc, at the time of installation.

Spread the love

WordPress Minimum Requirement : Tutorial 2

Chapter:2-Before Installation
Minimum Requirement of a system to run the WordPress
  • We need a server to run the PHP script, because PHP is a server side
    script and WordPress is based on PHP.
  • WAMP Server which is-Windows Apache MySQL PHP
  • Download Source code of WordPress from: http://wordpress.org/downloads
  • Latest  version of WordPress is wordpress-3.8.1 (as on 03-04-2014)
  • Latest of WAMP is 2.2 having
    • Apache 2.2.22
    • Mysql 5.5.24
    • PHP 5.3.13
    • PhpMyadmin 3.4.10.1
  • Apache is an open source web server , which is available in free. Apache is the one of the most popular and the most lovable web server by the web developers across the world.Separately we can download from: http://www.apache.org
  • MySQL is the most preferred open source RDBMS .
  • Very identical to MSSQL and other RDBMSs.
  • PHP(PHP Hypertext Preprocessor) is an open source server side scripting language having the features of OOPS and syntax similar to C
    Programming and Perl.
  • PHP provide a rich library to manipulate data and make most of the
    complicated data operations easy.
Spread the love

WordPress Inroduction : Tutorial 1

  • WordPress is a world famous Open Source CMS. Based on PHP as an open source server side scripting language.
  • WordPress is a free and open source blogging tool and a content management system (CMS) based on PHP and MySQL, which runs on a web hosting service.Features include a plug-in architecture and a template system.
  • WordPress is used by more than 18.9% of the top 10 million websites as of August 2013. WordPress is the most popular blogging system in use on the Web, at more than 60 million websites.
  • Architecture of template:
History:
  • WordPress started in 2003 with a single bit of code to enhance the typography of everyday writing and with fewer users than you can count on your fingers and toes. Since then it has grown to be the largest self-hosted blogging tool in the world, used on millions of sites and seen by tens of millions of people every day.
  • It was first released on May 27, 2003, by its founders, Matt Mullenweg and Mike Little,as a fork of b2/cafelog. As of February 19, 2014, version 3.8 had been downloaded more than 20 million times.The license under which WordPress software is released is the GPLv2 (or later) from the Free Software Foundation.
Content Management Bystem (CMS)
  • A Computer Application that allows publishing, editing and modifying content  as well as maintenance from a central interface.
  • CMSs are often used to run websites containing blogs, news, and shopping. Many corporate and marketing websites use CMSs. CMSs typically aim to avoid the need for hand coding but may support it for specific elements or entire pages.
  • The function and use of content management systems is to store and organize files, and provide version-controlled access to their data. CMS features vary widely. Simple systems showcase a handful of features, while other releases, notably enterprise systems, offer more complex and powerful functions. Most CMS include Web-based publishing, format management, revision control (version control), indexing, search, and retrieval. The CMS increments the version number when new updates are added to an already-existing file.

Architecture of wordpress template:

 

Spread the love

WordPress Advance Interview Questions and Answers

How can we create a CTP in wordpress?
CTP means Custom Post Type. We can create our own custom post types in wordpress besides the default post. We have to use wordpress core to implement this feature. We can add Product type, property type using CTP .
Example is given as follows:

<?php
function create_post_type() {
      register_post_type( 'Custom CPT',
        array(
          'labels' => array(
            'name' => __( 'Name of your CPT' ),
            'singular_name' => __( 'Name of your CPT' )
          ),
          'public' => true,
          'has_archive' => true,
        )
      );
    }
?>
add_action( 'init', 'create_post_type' );

Write custom query to list recent five posts?
Using WP_Query() method we can create custom wordpress queries. An example is given below:

<?php
$args = Array('post_type' => 'post', 'posts_per_page' => '5' );
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) : 
   while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <?php endwhile; ?>
<?php else : ?>
    <p> no posts found</p>
<?php endif; ?>

How can we create a widget area?
We can create a widget using the code given in example:

<?php
function create_widget() {

    register_sidebar( array(
        'name'          => 'My Widget Area',
        'id'            => 'my_widget',
        'before_widget' => '<div>',
        'after_widget'  => '</div>',
        'before_title'  => '<h2 class="title-widget">',
        'after_title'   => '</h2>',
    ) );

}
add_action( 'widgets_init', 'create_widget' );
?>

How we will add new navigation menu in footer?
Register a new menu and after calling this menu at proper place in footer template we can add a Footer menu.

How to display menus with container and additional css class?
We can add classes and ids ate the time of dislaying menu. We have to pass the values of parameters in function in wp_nav_menu();


What is the default directory to store images and other files in wordpress uploaded by user?
The default directory to stote files in wordpress is uploads folder. Using wp_upload_dir() we can get the path of current uploading directory.

What is excerpt?
An excerpt is a post summary .Placing a tag
we can create an excert for a post automatically.

How we can get page id or post id in wordpress?
We can use “get_the_ID()” function to get page or post id.
For Example:

    <?php
      while ( have_posts() ) : the_post();
            echo get_the_ID(); ?>
      endwhile; 
    ?>

How we will add a post meta post?
Wordpress has a function add_post_meta(). We can use an unique key to identify this meta for a particular post.



How we will check a logged in user in wordpress?
Wordpress function is_user_logged_in() is used to check logged in user.

What are sort code?
ShortCode is a specific code that allow you to do things with less effort. Shortcode is allow to execute code in post, page, and widget without writing any code. Shortcode can be used directly in post’s/page’s editor and in widget also.
In php file, shortcode should be called as suggested:

<?php do_shortcode('Here paste your plugin shortcode'); ?> 



Which Text Editor does wordpress use?
WordPress uses the TinyMCE Editor.

Spread the love

WordPress Basic Interview Questions and Answers

 What is WordPress?

WordPress is a content management tool and available as an open source. It is based on PHP-MySQL application.Nowadays WordPress is used for blogs, informational sites, e-commerce store, learning management system, booking systems and for various applications.
What is a CMS?
A CMS is a tool to manage content for a website. It provides the dynamic functionality to change, add design. A CMS can be used to manage various type organized data. WordPress is the most popular CMS.

What is the latest stable version running of WordPress?
Wordpress updates frequently. It has a giant community of contributors and a team of world-class programmers and Technocrats. We can find the latest version on www.wordpress.org.
What is difference between wordpress.org and wordpress.com?
wordpress.org provide the official software, themes, plugins, documentation of WordPress. Whereas wordpress.com is a hosting service. You can host your free blogs and sites on wordpress.com. it has pre-installed WordPress latest version.
What is a post in WordPress?
A post is an article that you publish on your blog.Post make a sense of blogging. here you can publish your day to day activity, articles, notifications.
What is a page in WordPress?
Pages are the landing pages that remain static on the website. Like, contact us, about us, team, Homepage.
What are the features of WordPress that make it most popular CMS?
What is a plugin in WordPress?
A plugin is an executable code snippet, that enhances the WordPress functionality. WordPress has unlimited flexibility to modify its functionality and to add new functionality. We can add features to WordPress without touching the core of software and plugins do that. We have plugins for various purposes. For example, Contact Form, Google Map, gallery, Menu, Font style, Slider etc.
What is custom post type – CTP ?
Wordpress has the flexibility to define the content type. It has Post and Page as the core, but we can create our own content type. This is called Custom Post Type or CTP.
What is taxonomy?
Taxonomy is a term that uses a word to group the contents and content types.We have a category, tag, Link Category, Post formats as default taxonomies.
Which types of application we can develop using WordPress?
Wordpress is used for varieties of applications like Informative Websites, E-commerce, Learning Management System, Ticket Booking Management, Hotel Booking, and rental, Printing Customization, news and media channel websites, Forums etc.
What is woo commerce?
Woocommerce is a plugin that converts a simple WordPress site into a fully functional e-commerce portal.
What is a theme in WordPress?
A theme is a complete package of application that changes the functionality, UI of the WordPress site as defined inside it. A theme contains Stylesheets, templates, javascript, function file, header, footer, page and post page.
What is style.css in WordPress?
The main style sheet of the theme is style.css by default. It also contains the theme Information.This is one of the mandatory parts of a theme.
What is a child theme in WordPress?
A child theme is an option to modify a theme, without changing its core files.
What are widgets in WordPress?
Widgets are the UI segments that are replaceable and easily manageable from admin side.A widget is dragged and dropped into the widget area. The widget provides additional flexibility to templates.
What is a hook? What are the difference between actions and filters in WordPress?
Hook allows us to hook a function with WordPress native functions.There are two types of hooks (1) Action and (2) Filter.Actions are the post events functions. they are followed by some other functions. For example, we can add an action to recent post display and It will be called when the recent post function will be called. Filters are the rewriting of functions. A filter modifies the function with that it will be hooked.
How can we export content from a WordPress site?
Wordpress has inbuilt tool for export and import contents. We can import content using XML file or we can export our content to an XML file.
Where we will find the menu section in admin?
We can find the menu section in the appearance section. We can manage various types of menu and their location from here. We can add items or remove items from the menu.
Does WordPress produce SEO friendly URLs?
Wordpress possesses a very strong in-page SEO feature. It has the option to modify the URL and make it SEO friendly. We can also modify meta content, title etc.
What is permalink?
Permalink is URL of post, page, media etc. We can modify it while editing the post or page.
What is a meta in WordPress?
Meta provides a metadata type structure for WordPress. We can add additional fields and their values using meta.
What is the usual meta used in WordPress?
There are many types of meta in WordPress as post meta, user meta, term meta, comment meta.
What are the default roles exist for WordPress users?
There are 5 default roles exist in WordPress are:
1-Administrator,
2-Subscriber,
3-Contributor,
4-Author,
5-Editor
Is WordPress an open source?
Yes, WordPress is an Open Source and freely available to use under GPL.
What server-side scripting language used by WordPress?
PHP is used as the serverside scripting language in WordPress.
What are the templates in WordPress?
Templates are the different types of page layout in WordPress. We can choose one of them while posting or adding content.

Spread the love