Posts

Showing posts from May, 2016

CMB2 Meta Box Code

function cmb_meta_box(array $mitul){ $prefix = '_xx_'; $mitul[] = array( 'id' => 'second-section', 'title' => 'This is Second section', 'object_types' => array('post'), 'fields' => array( array( 'name' => 'Enter Your Name', 'type' => 'text', 'id' => $prefix.'hkname' ) ) ); return $mitul; } add_filter('cmb2_meta_boxes','cmb_meta_box');

Raw Code Meta Box

//functions.php function favourite_food(){ add_meta_box( 'fav_food_meta', 'What is your Favourite Food ???', 'meta_box_op', 'page', 'normal' ); } add_action('add_meta_boxes','favourite_food'); function meta_box_op($post){ ?> <label for="food">Type your favourite food</label> <p><input type="text" id="food" name="zboom_food" class="widefat" value="<?php echo get_post_meta($post->ID,'zboom_food',true); ?>" /></p> <?php } function food_send_to_database($post_id){ update_post_meta($post_id,'zboom_food',$_POST['zboom_food']); } add_action('save_post','food_send_to_database'); //page.php <?php echo get_post_meta($post->ID,'zboom_food',true); ?>

What is callback function ?

A callback function also known as a higher-order function is, a function that is passed to another function as a parameter, and the callback function is called inside the other function.

WP read_more($limit);

WordPress read_more($limit); function with limitation. Code and explanation is given below. //functions.php function read_more($limit){ $content = explode(' ', get_the_content()); $less_content = array_slice($content, 0, $limit); echo implode(" ", $less_content); } //page.php read_more(10); Function's explanation : First we make a function with a parameter which through we will pass the limit of contents. Then we take a variable named $content which containing explode (php) function. What explode function do actually ?? explode(); convert contents in to array basis on which you define. It can be space or any character. explode(); function has two parameter. First one is for the exact context which divide the content into two array. We have define here space ' '. So according to our statement where it will get space it will built array. And using space in first parameter we have made each word in an array. Second parameter is for

WP function : get_post_meta();

get_post_meta(); function has three parameter. First parameter is for define page or post id. We can statically define the first parameter or dynamically. If we want to dynamically define the first parameter then we have use another function which is get_the_ID(). In the second parameter we will choose a unique id and the third parameter is Boolean (true/false). We will write true in the Boolean parameter.   

Three important thing in HTML

Image
1. Tag 2. Element 3. Attribute Tag is a specific thing. Element is a complete thing. Attribute define in the opening tag and modify the elements till the closing tag which in it. Example : <p align="center">This is Element Content</p> Attribute Visual Example :  Element Visual Example : 

To easily generate favicon

http://www.favicon-generator.org/ 

WP Admin Menu Position

2. Dashboard 4. Separator 5. Posts 10. Media 15. Links 20. Pages 25. Comments 59. Separator 60. Appearance 65. Plugins 70. Users 75. Tools 80. Settings 99. Separator

Create WP User

functions.php $newser = new WP_User(wp_create_user('kamal','123','hkc@gmail.com')); $newser->set_role('administrator');