Wordpress - 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

Спасибо


person Wasteland    schedule 16.08.2018    source источник


Ответы (1)


вы используете неправильную функцию для создания шорткода

Используйте add_shortcode для создания шорткода, а не add_action

Пожалуйста, используйте этот код ..

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