Showing posts with label Wordpress. Show all posts
Showing posts with label Wordpress. Show all posts

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>


Tuesday 10 March 2015

How do I get wordpress global variable and functions in custom file [SOLVED]

How do I get wordpress global variable and functions in custom file


Problem:
I have create a file i.e mytestfile.php in root folder of wordpress blog.
Full path of mytestfile.php is http://www.example.com/blog/mytestfile.php.
Now, I want to access all global variables, functions like $wp_query, query_posts.



Solution:
As you have created mytestfile.php in blog root folder.
Just add the following line in top. This will load wordpress blog and you can access global variables.
require( 'wp-load.php' );
global $wp_query;
Now, you can access $wp_query, query_posts.



Tuesday 17 February 2015

How to send Email in wordpress

How to send Email in wordpress

In Websites, we need to send email on Registration, Forget password, order to our Clients/Customer. If your email template is ready Sending email is a very quick step in WordPress, but sometimes developer gets confused due to not available of correct email sending code.

In this post, We will give you code snippet. This code snippet will send email. You can set the receipt, subject, description, reply-to and header  in email.

$receipt = "user@no-spam.ws"; 
$subject = "This is subject";
$content = 'This is conent of the email.


http://www.web-technology-experts-notes.in';
/** Set the Reply -optional field **/
$headers = array(
 'Reply-To' => "replyto@no-spam.ws"
);
/** Set the Reply -optional field **/


/** Send the Html email - optional field **/
add_filter( 'wp_mail_content_type', 'set_html_content_type' );
/** Send the Html email - optional field **/

$status = wp_mail($receipt, $subject, $content, $headers);

if($status){
echo 'Sent Successfully';
}else{
echo 'Not send';
}
  


If above any query regarding above code, Please comment!.


Wednesday 28 January 2015

How to change the author of a post in Wordpress

How to change the author of a post in Wordpre


There are number of methods to change the author of word-press post and are following.




Method 1: Change Author by manually edit the POST, Follow the simple steps. 
  • Login as Administrator.
  • Go to Posts.
  • Edit the post which's author you want to change.
  • Now you are on edit post.
  • Scroll down till you get "Author List" under "Author".
  • Now select the Author from dropdown/selectbox to whom you want to assign. 
  • See screenshot below

Wordpress how to change the author of a post by manually




Method 2: Change Author by MySQL edit the POST, Follow the simple steps
  • Login to your database.
  • Get the backup of wp_posts table, incase you want to revert back.
  • Get the post_author of author which post you want to assgin another user (Suppose post_author is 28).
  • Get the post_author of author to whom you want to assign.(Suppose post_author is 30).
  • Execute the Following MySQL Query.
  • update wp_posts set post_author="30" where post_author="28"
  • It will change the author of all post from one author (28) to another author (30)


Thursday 22 January 2015

How can delete a user without deleting the post and comments in wordpress?

How can delete a user without deleting the post and comments in wordpress?

In this blog, I will expalin how to delete a user/Editor/Subscriber/Author/Administor without deleting the post and comments. When you start deleting the post application will be prompt that you want to assign the post to another user. To keep the user's post, this you have to assign the deleteing user post to another user.


Follow the following simple steps.
1. Login as Administrator (must be not login to whom you are going to delete).
2. Go to User Listing.
3. Click on check box in front of user to whom you want to delete. See below screenshot.
wordpress admin user listing



4. Click on delete icon. It will bring to you new page.
5. Now assign all post to another user/administrator. See below Screenshot.
wordpress admin user delete page

6. Click on "Confirm Deletion". User deleted successfully.

Now deleting the user, same user wouldn't be able to login to system. If he is currently login will logout automatically.