Monday 20 April 2015

Wordpress Interview Questions and Answers for experienced

Wordpress interview questions and answers experienced

Question: How to create a folder if it doesn't already exist in Wordpress?
$pathname='path/to/directory';
if (!file_exists($pathname)) {
    mkdir($pathname, 0777, true);
}

In mkdir have following 3 parameters.
Pathname: path where you want to create the folder
Folder Permission: Permission of folder.
Recursive: true for all sub directory, false for current directory only.


Question: What is difference between mode value 0777 and 777 in mkdir/chmod function?
In PHP, 0777 and 777 have same meaning and no difference.
When you are providing 4 digit in for permission, it means 1 digit will be used for sticky bit.
sticky bit is access right flag that can be assigned to files and directories on Unix-like systems.


Question: Where to place to insert the google analytics Code?
You should add "Google analytics code" in Every page, so that you can get all pages tracking report.
As per google, you should add "Google Analytics code" just before the closing of "head" for better results.
https://support.google.com/analytics/answer/1008080?hl=en

In wordpress, when we are using some theme for displaying your website. there might be textbox in admin section, to add the "Google Analytics" code for tracking purpose.(May OR may not available in your current theme)


Question: How to get the current page name in WordPress?
You can get the page name from below of two?
$slug = basename(get_permalink());
OR
$pagename = get_query_var('pagename');  



Question: How do I ge the version of wordpress?
echo bloginfo('version');
Above is get from below file.
You can check in wp-includes/version.php
$wp_version = '4.1.2';



Question: How to turn off the Notice/Warning from my wordpress website?
Open the wp-config.php file and WP_DEBUG set the false.
define('WP_DEBUG', false );


Question: What is use of __() and _e() functions in wordpress?
These are function used when you website multilingual.
each of this function have two parameter.
1st parameter: String which you want to convert from one language to another.
2nd parameter: domain name.
 $translatedText = __( 'TEXT_FOR_TRANSLATION', 'textdomain' ); //This will return the translated text
 _e( 'TEXT_FOR_TRANSLATION', 'textdomain' ); //This will print the translated text



Question: How to get wordpress post featured image URL?
if (has_post_thumbnail( $post->ID ) ){ 
  $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
  echo $image[0];//image url 
}



Question: How to get last inserted row id from wordpress database?
global $wpdb;
/** insert query here with $wpdb**/
/** insert query here with $wpdb**/
 $lastId = $wpdb->insert_id; //This is last insert id



Question: How to Remove P and Br tags in WordPress posts?
Open functions.php in your current active theme.
Add following lines

remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );

http://codex.wordpress.org/Function_Reference/wpautop




Question: How do I get current taxonomy "term id" on wordpress?
$obj = get_queried_object();
echo $obj->term_id;



Question: How do I add Syntax Highlighting on wordpress.com?
As you can't install plugin for syntax high lighting in wordpress.com, you can use existing syntax highligher.
[sourcecode language='python']

[/sourcecode]



Question: How to check admin login or Not?
if(is_admin()) { 
/** Write your code here */

/** Write your code here */
}



How to protect your website from DDos Attack?
Add following code in your .htaccess file.
<files xmlrpc.php>
      order allow,deny
      deny from all
    </files>