【问题标题】:Wordpress - Gutenberg - shortcode not renderingWordpress - Gutenberg - 短代码不呈现
【发布时间】:2018-08-16 06:25:20
【问题描述】:

我已打开 Gutenberg 并尝试在页面上创建简码。这是我在functions.php中的代码

// Enable shortcodes in text areas
add_filter( 'widget_text', 'shortcode_unautop');
add_filter( 'widget_text', 'do_shortcode');

// Enable shortcodes
add_filter( 'the_excerpt', 'shortcode_unautop');
add_filter( 'the_excerpt', 'do_shortcode');


function first_shortcode() { 
	$content = '<h1>This is my first shortcode</h1>';
	return $content;
}
add_action('my_shortcode','first_shortcode');

在帖子中,我将 [my_shortcode] 放在简码部分,如下:

但是当我显示页面时,它只会呈现 [my_shortcode]。我正在运行 Wordpress 4.9.8

谢谢

【问题讨论】:

    标签: wordpress shortcode wordpress-gutenberg


    【解决方案1】:

    你使用了错误的函数来生成简码

    使用add_shortcode 创建短代码而不是add_action

    请使用此代码..

    function first_shortcode() { 
      $content = '<h1>This is my first shortcode</h1>';
      return $content;
    }
    add_shortcode('my_shortcode', 'first_shortcode');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-28
      • 2021-04-11
      • 1970-01-01
      • 2018-08-15
      • 2021-01-16
      • 1970-01-01
      • 2018-05-06
      • 2016-06-17
      相关资源
      最近更新 更多