我想在一个单独的页面上显示注册课程,使用一个短代码调用前端的插件函数。我应该使用哪个add\\u shortcode函数?下面是我试图调用的函数
$enrolled_course = tutor_utils()->get_enrolled_courses_by_user();
我想在一个单独的页面上显示注册课程,使用一个短代码调用前端的插件函数。我应该使用哪个add\\u shortcode函数?下面是我试图调用的函数
$enrolled_course = tutor_utils()->get_enrolled_courses_by_user();
Step 1 定义您的快捷码回调函数。您可以找到一些生成输出的示例here.
function your_shortcode_callback( $atts ) {
// if attributes as used with shortcode, then do something with $atts
// get data
$enrolled_course = tutor_utils()->get_enrolled_courses_by_user();
// do something to turn the data into html string
$output_html = \'\';
// callback should return its output
return $output_html;
}
Step 2 注册短代码。名称可以是您喜欢的任何名称,只要它是唯一的add_shortcode( \'whatever_you_like_as_shortcode_name\', \'your_shortcode_callback\' );
Step 3 使用短代码[whatever_you_like_as_shortcode_name]
有关更多详细信息,请参阅Shortcode API Codex entry.可以将快捷码回调和注册添加到a custom plugin 或主题的functions.php
文件