Created
February 16, 2017 17:05
-
-
Save nicolabavaro/6c79a33a70aed8820080fbd2a4f3c32e to your computer and use it in GitHub Desktop.
Create a custom element fo visual Composer Grid Builder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// _dt_fancy_header_bg_image | |
add_filter( 'vc_gitem_template_attribute_fancy_image', 'vc_gitem_template_attribute_fancy_image', 10, 2 ); | |
function vc_gitem_template_attribute_fancy_image( $value, $data ) { | |
/** | |
* @var Wp_Post $post | |
* @var string $data | |
*/ | |
global $post; | |
$output = ''; | |
$postID = $post->ID; | |
$fancy_head_ID = get_post_meta( $post->ID, '_dt_fancy_header_bg_image', true ); | |
$image_string = wp_get_attachment_image( $fancy_head_ID[0], 'medium' ); | |
$output .= "\n\t" . '<div class="' . $css_class . '">'; | |
$output .= "\n\t\t" . '<div class="wpb_wrapper">'; | |
$output .= "\n\t\t\t" . $image_string; | |
$output .= "\n\t\t" . '</div> '; | |
$output .= "\n\t" . '</div> '; | |
// return a template for featured_image variable | |
//return vc_include_template( 'params/vc_grid_item/attributes/fancy_image.php', array( | |
//'post' => $post, | |
//'data' => $data | |
//) ); | |
return $output; | |
} | |
add_filter( 'vc_grid_item_shortcodes', 'my_module_add_grid_shortcodes' ); | |
function my_module_add_grid_shortcodes( $shortcodes ) { | |
$shortcodes['vc_batt_image'] = array( | |
'name' => __( 'Post Image2', 'js_composer' ), | |
'base' => 'vc_batt_image', | |
'icon' => 'vc_icon-vc-gitem-image', | |
'category' => __( 'Post', 'js_composer' ), | |
'description' => __( 'Featured image', 'js_composer' ), | |
'post_type' => Vc_Grid_Item_Editor::postType(), | |
); | |
return $shortcodes; | |
} | |
add_shortcode( 'vc_batt_image', 'vc_gitem_fancy_image_render' ); | |
function vc_gitem_fancy_image_render( $atts ) { | |
return '{{fancy_image: }}'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment