Wordpress - 古腾堡 - 短代码不呈现

Was*_*and 0 wordpress shortcode wordpress-gutenberg

我打开了 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');
Run Code Online (Sandbox Code Playgroud)

在帖子中,我将 [my_shortcode] 放在了短代码部分,如下所示:

在此处输入图片说明

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

谢谢

Yog*_*arg 5

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

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

请使用此代码..

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