简体   繁体   English

在自定义简码中调用未定义的函数do_shortcode

[英]Call to undefined function do_shortcode in custom shortcode

I'm creating a custom element for the WPBakery plugin and receiving an error when adding do_shortcode($content) . 我正在为WPBakery插件创建一个自定义元素,并在添加do_shortcode($content)时收到错误。

My element is named hero.php and its function is as follows (in WPBakery): 我的元素名为hero.php ,其功能如下(在WPBakery中):

  • User selects hero module from option ( hero_html() ). 用户从选项( hero_html() )中选择英雄模块。
  • User can then (within the hero module) chose to add a slide ( hero_content_html() ). 然后,用户可以(在hero模块中)选择添加幻灯片( hero_content_html() )。

Visual: 视觉效果:

在此处输入图片说明

A var_dump($content) spits out the fields and values, which are correct, but unsure why do_shortcode is undefined? var_dump($content)吐出正确的字段和值,但不确定为什么do_shortcode未定义?

Below is where the function is called: 下面是调用该函数的位置:

 <?php public function hero_html( $atts, $content = null) { $output = $el_class = extract( shortcode_atts( array( 'el_class' => '', 'css' => '', ), $atts ) ); static $i = 0; $output = '<div id="slickslider-'.$i++.'">'.do_shortcode($content).'</div>'; return $output; } public function hero_content_html( $atts, $content = null ) { $output = $title = extract( shortcode_atts( array( 'title' => '', ), $atts ) ); $output .= ' <!-- Slide --> <div class="heroSlider">'; $output .= ' <div class="container"> <div class="row"> <div class="col-10"> '(!empty($title) ? '<h1>' . $title . '</h1>' : "" );' </div> </div> </div> </div> <!-- Slide --> '; return $output; } } ?> 

Please check for the file wp-load.php whether it's being loaded before this page or not. 请检查文件wp-load.php是否在此页面之前被加载。 For running do_shortcode() ,wp-load.php is required. 为了运行do_shortcode(),需要wp-load.php。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM