WP Bakery自定义模板变量不起作用

时间:2018-05-03 19:07:28

标签: wordpress visual-composer

我尝试在网格构建器中添加自定义短代码。短代码按预期工作,但打印值为空。

add_filter( 'vc_grid_item_shortcodes', 'my_module_add_grid_shortcodes' );
function my_module_add_grid_shortcodes( $shortcodes ) {
   $shortcodes['vc_custom_post_press_link'] = array(
      'name' => __( 'Press link', 'domain' ),
      'base' => 'vc_custom_post_press_link',
      'category' => __( 'Content', 'my-text-domain' ),
      'description' => __( 'Show custom post meta', 'my-text-domain' ),
      'post_type' => Vc_Grid_Item_Editor::postType(),
   );

   return $shortcodes;
}

// output function
add_shortcode( 'vc_custom_post_press_link', 'vc_custom_post_press_link_render' );
function vc_custom_post_press_link_render($atts, $content, $tag) {
   return 'test1 {{ press_link }}';
}

add_filter( 'vc_gitem_template_attribute_press_link', 'vc_gitem_template_attribute_press_link ', 10, 2 );
function vc_gitem_template_attribute_press_link( $value, $data ) {
   return 'test2';
}

预期输出应为

test1 test2

但我只得到

test1

原始代码来自the official doc,但它似乎无法运作。

修改 我刚试过,文档中的代码也不行。我想它没有更新。我需要一种方法来获取ACF字段的值并在其周围添加一些HTML。

1 个答案:

答案 0 :(得分:0)

解决!问题出在这一行

add_filter( 'vc_gitem_template_attribute_press_link', 'vc_gitem_template_attribute_press_link ', 10, 2 );

应该是

add_filter( 'vc_gitem_template_attribute_press_link', 'vc_gitem_template_attribute_press_link', 10, 2 );

注意vc_gitem_template_attribute_press_link末尾缺少的空格。