我找到了解决方案。通过扩展 WPBakeryShortCode 类,您可以更改 contentAdmin 输出:
// Extend Class WPBakeryShortCodesContainer
if (class_exists('WPBakeryShortCode')) {
class WPBakeryShortCode_Custom_Element extends WPBakeryShortCode {
/**
* @param $atts
* @param $content
*
* @return string
* @throws \Exception
*/
public function contentAdmin( $atts, $content = null ) {
$output = $custom_markup = $width = $el_position = '';
if ( null !== $content ) {
$content = wpautop( stripslashes( $content ) );
}
$shortcode_attributes = array( 'width' => '1/1' );
$atts = vc_map_get_attributes( $this->getShortcode(), $atts ) + $shortcode_attributes;
$this->atts = $atts;
$elem = $this->getElementHolder( $width );
if ( isset( $this->settings['custom_markup'] ) && '' !== $this->settings['custom_markup'] ) {
$markup = $this->settings['custom_markup'];
$elem = str_ireplace( '%wpb_element_content%', $this->customMarkup( $markup, $content ), $elem );
$output .= $elem;
} else {
$inner = $this->outputTitle( $this->settings['name'] );
$inner .= $this->paramsHtmlHolders( $atts );
$elem = str_ireplace( '%wpb_element_content%', $inner, $elem );
$output .= $elem;
}
return $output;
}
}
}
我按照这个 Git 示例创建我的自定义元素:https ://gist.github.com/Webcreations907/ff0b068c5c364f63e45d