Skip to content

Instantly share code, notes, and snippets.

@atxiii
Last active November 29, 2020 15:32
Show Gist options
  • Save atxiii/430ba9ae646577a128bc25c1cb491dfe to your computer and use it in GitHub Desktop.
Save atxiii/430ba9ae646577a128bc25c1cb491dfe to your computer and use it in GitHub Desktop.
Adding Avatar Shortcode to WPBakery Page Builder Grid Builder
<?php
add_filter( 'vc_grid_item_shortcodes', 'my_module_add_grid_shortcodes' );
function my_module_add_grid_shortcodes( $shortcodes ) {
$shortcodes['vc_avatarino'] = array(
'name' => __( 'Avatar', 'mrcatdev' ),
'base' => 'vc_avatarino',
'category' => __( 'Content', 'mrcatdev' ),
'description' => __( 'Avatar', 'mrcatdev' ),
'post_type' => Vc_Grid_Item_Editor::postType(),
);
return $shortcodes;
}
add_shortcode( 'vc_avatarino', 'vc_avatarino_func' );
function vc_avatarino_func() {
return '{{avatarino}}';
}
add_filter( 'vc_gitem_template_attribute_avatarino','vc_gitem_template_attribute_avatarino', 10, 2 );
function vc_gitem_template_attribute_avatarino( $value, $data ) {
extract( array_merge( array(
'post' => null,
'data' => '',
), $data ) );
$atts_extended = array();
parse_str( $data, $atts_extended );
$atts = $atts_extended['atts'];
// write all your widget code in here using queries etc
$user =$post->author;
$avatar =get_avatar(get_the_author_meta('ID',$user),96);
$author_name = get_the_author_meta('nickname',$user);
$out = '<div class="post-details"><span class="grid-avatar">'.$avatar.'</span><span class="grid-details"><span class="author">'.$author_name.'</span><span class="post-date">'.$post->post_date.'</span></span></div>';
return $out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment