Posts

Showing posts from January, 2019

WP register_post_type() with custom CMB2 meta box

functions.php register_post_type('portfolio',[ 'labels'=>[ 'name'=> 'Portfolio', 'add_new_item'=>'Add new portfolio', 'view_item'=>'View portfolio', ], 'public'=>true, 'menu_icon'=>'dashicons-edit', 'menu_position'=>1, 'supports'=> ['title','editor','thumbnail'] ]); custom.php add_action('cmb2_admin_init','custom_metaboxes'); function custom_metaboxes(){ $portfolioMetaBox = new_cmb2_box([ 'object_types'=>['portfolio'], 'id'=>'portfolio-additional-fields', 'title'=>'Portfolio Additional Fields' ]); $portfolioMetaBox->add_field([ 'id'=>'portfolio_designation', 'name'=>'Portfoilo Designation', 'type'=>'text' ]); $portfolioMetaBox->add_field([ 

add_filter() function in WP

function filtering($a){ echo "<h5> $a </h5>"; } add_filter('the_title','filtering'); add_filter() function has two parameters 1st : The function/hook which will be filtered 2nd : Filtering will done by which function

WP Hook Creation

functions.php {Back end} //A function named basicHook which have two parameters $a and $b. function basicHook($a,$b){ echo "First Value : $a <br/>"; echo "Second Value : $b <br/>"; } //Creating the hook : 1st parameter : hook name 2nd parameter : executing function 3rd parameter : executing priority 4th parameter : maximum number of parameters acceptance in the hook add_action('ahook','basicHook',1,2); header.php {Front end} //Calling the hook from front end by the function named do_action(); 1st parameter : defined hook name 2nd and 3rd parameter hook value. do_action('ahook',500,600);