Wednesday, March 19, 2014

What is hooks and types of hooks in wordpress?Where it used?

Ans. Hooks are provided by WordPress to allow your plugin to ‘hook into’ WordPress; that is, to call functions in your plugin at specific times, and thereby set your plugin in motion. There are two types of hooks used in WordPress are Actions and Filters.
1)Actions Run During a Typical Request.for example A developer may want to add code to the footer of a Theme. This could be accomplished by writing new function, then Hooking it to the wp_footer Action.
has_action()
add_action()
do_action()
do_action_ref_array()
did_action()
remove_action()
remove_all_actions()
2)Filters are the hooks that WordPress launches to modify text of various types before adding it to the database or sending it to the browser screen.
has_filter()
add_filter()
apply_filters()
apply_filters_ref_array()
current_filter()
remove_filter()
remove_all_filters()

How to add option for open menu item in new tab?

Ans. This is very basic feature but sometime developer never use this so they have no idea and goto code and add manually that links.For add option in menu item for open link in new tab just navigate to “Screen Option” at top right corner in menu select check “link target”. See below screenshot.
Menus

How to Change the Length of the Default WordPress Excerpt.

Ans The default WordPress excerpt is 55 words long. By modified bit to your functions.php file you can change the length to as you required.Below is the code if we need 60 length.

How to Change Your Default WordPress Post Category & Post Type?

Ans. Most common issue and most of developer not know this and find hacking(custom coding solution).But it more easy then that.simply navigate to Settings > Writing > and then look for the pull down menu beside “Default Post Categoy.” for change default category selection.
Writing Setting
Below that you can find Default post format for changes post type from standard to image post type or a video post type,chat gallery,link and many more.

How to run database Query in WordPress?

The $wpdb->query function allows you to execute any SQL query on the WordPress database. It is best to use a more specific function. Check sample code below for SELECT query.

What is the use of loop in Worpdress Where we used it?

Ans. The Loop are php code used by WordPress to display posts. Using The Loop, WordPress processes each post to be displayed on the current page.check below sample code.

What are the custom fields in wordpress? How to display it?

Ans We will add extra information to our post by using custom fields.Custom Fields are a form of meta-data that allows us to store arbitrary information with each WordPress post.
To display the Custom Fields for each post, use the the_meta() template tag.
To fetch meta values use the get_post_meta() function.
For example we use custom fields:-

How to hide Directory Browsing in WordPress from server using .htaccess file?

By default when your web server does not find an index file (i.e. a file like index.php or index.html), it automatically displays an index page showing the contents of the directory.SO now if you want to hide this add below code in .htaccess file.