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

Friday 5 August 2016

What html tags are allowed by

What html tags are allowed by

Question: What html tags are allowed by
Following HTML Tags are allowed in
h1, h2, h3, h4, h5, h6, header, hgroup, hr, i, img, ins, kbd, li, map, ol, p, pre, q, s, section, small, span, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, var

Question: Can we add javascript in
No, You can add.
script Tags are not allowed.

Question: How to embed youtube video?
Just add following code in post.

Question: Give list of URL which videos is allowed by
Flickr (both videos and images)
Google Video (only VideoPress-type videos for the time being)
SmugMug (WordPress 3.0+) (WordPress 3.0+)

Wednesday 13 April 2016

How to create wordpress Shortcode?

How to create wordpress Shortcode?

Question: What is Shortcode in Wordpress?
A shortcode is code that lets you do nifty things with very little effort.

Question: What is use Shortcode in Wordpress?
Shortcodes can be embed in post Or page which can do lot of things like Image Gallery, Video listing etc.

Question: Give a simple Shortcode example?

It would add photo gallery of images attached to that post or page.

Question: What is Shortcode API in Wordpress?
Shortcode API is set of functions for creating shortcodes in Page and Post.

The Shortcode API also support attributes like below:
[gallery id="123" size="large"]

Question: What is name of function which is used to register a shortcode handler?

It has two parameter.
first is shortcode name and second callback function. For Example:
add_shortcode( 'shortcode', 'shortcode_handler' );

Question: How many parameter can be passed in callback function?
  1. $atts - an associative array of attributes.
  2. $content - the enclosed content
  3. $tag - the shortcode tag, useful for shared callback functions

Question: How to create shortcode in wordpress? Give working example? Create Shortcode
function testdata_function() {
  return 'This is testing data. This is testing data. This is testing data. This is testing data. This is testing data. This is testing data.';
add_shortcode('testdata', 'testdata_function');

Use Shortcode

Question: How to create shortcode with attributes in wordpress? Give working example?
Create Shortcode
function testdata_function($atts) {
      'header' => 'This is default heading',
      'footer' => 'This is default footer',
   ), $atts));

  return '<b>'.$header.'</b>
This is testing data. This is testing data. This is testing data. This is testing data.
add_shortcode('testdata', 'testdata_function');

Use Shortcode
[testdata header="Custom Heading" footer="Custom footer"]

Question: How to create shortcode with in wordpress? Give working example?
Create Shortcode
function testdata_function($attr, $content) {
  return $content.' This is testing data. This is testing data. This is testing data. This is testing data. This is testing data. This is testing data.';
add_shortcode('testdata', 'testdata_function');

Use Shortcode
[testdata]This is content[/testdata]

Question: What to do if Ampersand (i.e &) converted to &#038;?
Use html_entity_decode function (PHP inbuilt function).

Question: How to use meta tags in shortcode?
If you want to add meta tags in head tag. then use below function.
add_action('wp_head', 'add_meta_tags');
function add_meta_tags() {
        echo '';

Saturday 9 January 2016

XMLRPC Wordpress Attack

How to protect your wordpress website from xmlrpc attack

Queston: What is XMLRPC?
XML-RPC is one of the protocols that use XML for messages between two server. It is used to "Remote Procedure Calls" using XML.

Queston: Question: What is JSON-RPC?
JSON-RPC is one of the protocols that use JSON for messages between two server.
It is used to "Remote Procedure Calls" using JSON.

Queston: What is xmlrpc in wordpress?
WordPress uses an XML-RPC interface.
XML-RPC protocol is used to post entries.

Question: How to protect your website from xmlrpc attack?
Add following code in bottom of .htaccess file in root folder.
<Files 'xmlrpc.php'>
Order Allow,Deny
deny from all

Question: How to stop abusing XML-RPC file?
Open functions.php file in your add theme and following code.
add_filter( 'xmlrpc_methods', function( $methods ) {
         unset( $methods[''] );
            return $methods;
      } ); 

Sunday 31 May 2015

Wordpress insert record into table and get last insert Id

Wordpress insert record into table and get last insert Id

In Wordpress, Record insertion into table is quite simple.
1. Create an Object of $wpdb;
2. Set the data in an Array.
3. Set the table name.
4. Use insert function  to insert record.
5. In insert function, first argument is table name and Second argument is array.

See Example Below:
global $wpdb;
$tableName = $wpdb->prefix . "users";
'user_login' => 'mylogin',
'user_nicename' => 'Poonam', 
'user_email' => '',
'user_registered' => date('Y-m-d H:i:s',time()),
'user_status' => '1',
'display_name' => 'Arun Kumar');

//Insert Into Database
$wpdb->insert( $tableName, $saveFieldArray);

//get the last inert Id
$lastInsertId = $wpdb->insert_id;  

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?
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.

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());
$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' );

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
As you can't install plugin for syntax high lighting in, you can use existing syntax highligher.
[sourcecode language='python']


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

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

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

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 = ""; 
$subject = "This is subject";
$content = 'This is conent of the email.';
/** Set the Reply -optional field **/
$headers = array(
 'Reply-To' => ""
/** 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);

echo 'Sent Successfully';
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.

Tuesday 20 January 2015

Wordpress redirect https to http with htaccess [SOLVED]

Wordpress redirect https to http with htaccess [SOLVED]

You can redirect all website pages from https to http. It will be redirect only when you open the page with https. 

See Example Below Redirect to Redirect to Redirect to

Open .htaccess in root folder
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Replace with Following code
RewriteEngine On

RewriteCond %{SERVER_PORT} ^443$ [OR]
RewriteCond %{HTTPS} on
RewriteRule  ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Friday 19 December 2014

Wordpress title repeated two times in browser header [SOLVED]

Wordpress title repeated two times in browser header [SOLVED]

I add the post from wordpress admin section (, 
After publishing the post it start displaying in website.

In Post detail page, Every information like post title, post description and post date etc is correct except meta title.

Issue: Meta title have post name + website name + | website name.

Here meta title have website name two times at then end of page title.

  • Login into admin section.
  • Go to Plugins section. ( or use link:
  • Search for "All in One SEO Pack".
  • Click on deactivate, Now "All in One SEO Pack" is deactivated successfully.
  • Go to website and refresh the Frontend page, Now you will see two times website name in title is FIXED.

Friday 12 December 2014

Wordpress Interview Questions and Answers

Wordpress Interview Questions and Answers

Wordpress is opensource content management system where you can add/update/delete contents from admin section. Content may be text, images or videos etc. 

Because it is opensource, so you can update the code at free of cost. Wordpress built on PHP/MySQL/javascript (which is also an Open Source) and licensed under GPL. You can create different types of websites whether it is personal / commercial website. Today most of developer prefer wordpress as its easy to install and millions of plugins, themes are available over internet at free of cost & you can do customization.  

Question: What is Wordpress?
Wordpress is Content Management System which have robust admin section. From Admin section you can manage the website text/html, image & videos etc. You can easily manage pages & posts. You can set meta title, meta description & meta keywords for each post. It gives you full control over post & pages .

Question: Is Wordpress opensource?
Yes, Wordpress is opensource and you can do customization as per your requirement. Wordpress is built in PHP/MySql/javascript/jQuery which is also an opensource.

Question: What is current stable version of wordpress?
4.1 released in November 20, 2014

Question: What kind of website can I build with WordPress?
WordPress was originally developed as a blogging in 2003 but now it has been changed a lot. you can create personal website as well as commercial website.
Following types of websites can be built in wordpress:
  • Informative Website
  • Personal Website
  • Photo Gallery
  • Business Website
  • E-Commerce website
  • Blogging
Today, million of free/paid wordpress themes, wordpress plugin are available which help you to create as per your requirement.

Question: From where you can download plugins?

Question: From where you can download themes?

Question: What is Hooks in wordpress?
Hooks allow user to create WordPress theme or plugin with shortcode without changing the original files.

Question: What are the types of hooks in WordPress?
Following are two types of hooks
A) Action hooks: This hooks allow you to insert an additional code.
B) Filter hooks: Filter hooks will only allow you to add a content or text at the end of the post.

Question: What are positive aspects of wordpress?
  • Easy to install and upgrade the wordpress
  • In-built SEO engine and you can manage the URL and meta data as per your requirement.
  • Easy to themes and plugins
  • Multilingual available in more than 70 languages
  • Can be do customization as per requirement
  • Lots of free/paid themes/plugin available

Question: What is the default prefix of wordpress tables?
wp_ is the prefix for wordpress but you can change at the time of installation.

Question: What is WordPress loop?
The Loop is PHP code used by WordPress to display posts.

Question: What are the template tags in WordPress?
Template tags is a code that instructs WordPress to "do" or "get" something

Question: What are meta tags in wordpress?
Meta-tags are keywords and description used to display website.

Question: How to secure your wordpress website?
  • Install security plug-ins like WP security
  • Change password of super admin OR other admin
  • Add security level checks at server level like folder/file permission.

Question: How many tables a default WordPress will have?
Following are main table in wordpress:
  • wp_commentmeta
  • wp_comments
  • wp_links
  • wp_options
  • wp_postmeta
  • wp_posts
  • wp_terms
  • wp_term_relationships
  • wp_term_taxonomy
  • wp_usermeta
  • wp_users

Question: How to hide the top admin bar at the frontend in WordPress?
Add following code functions.php
add_filter('show_admin_bar', '__return_false');

Question: How to hide Directory Browsing in WordPress from server?
Add following code in htaccess file
Options -Indexes

Question: How to display custom field in wordpress?
echo get_post_meta($post->ID, 'keyName', true); 

Question: How to run database Query in WordPress?
$wpdb->query("select * from $wpdb->posts   where ID>10 ");

Question: What types of hooks in wordpress is used?
1)Following are Actions hooks:.

2)Following are Filters hooks .

Question: How can you backup your WordPress content?
WordPress admin -> Tools -> Import

Question: List most commonly functions used in wordpress?
  • wp_nav_menu() :- Displays a navigation menu.
  • is_page() :- to check if this is page OR NOT, will return boolean value.
  • get_the_excerpt() :- Copy the excerpt of the post into a specified variable.
  • in_category() :- Check if the specified post is assigned to any of the specified categories OR not.
  • the_title():- Displays the title of the post in website.
  • the_content():- Displays the contents of the post in website.

Question: What are the file structure in wordpress.
Following are main files which used in wordpress
  • index.php :- for index page.
  • search.php :- For display the search result page.
  • single.php :- for single post page.
  • page.php :- display the static pages.
  • category.php :- Display the category page.
  • tag.php :- For display the tags page.
  • author.php :- For display author page.
  • taxonomy.php :- For display the taxonomy archive.
  • attachment.php :- For managing the single attachments page.
  • header.php :- For managing top part of page.
  • footer.php :- For manage bottom part of pages.
  • archive.php :- For archive page display.
  • 404.php :- For display 404 error page.