wordpress用短代码在前台调用将php文件的过程步骤:
1、在主题下面新建一个文:short_code件夹,把编写好的xxx.php文档放在这个文件夹里面。
《?php
global $current_user;
get_currentuserinfo();
echo get_avatar( $current_user->user_email, 32);
?》
2、打开主题的functions.php,编写调用代码:
// functions.php
function do_shortcode_my_script($atts, $content = null) {
include('path/to/my_script.php');
return '';
}
add_shortcode('my_script', 'do_shortcode_my_script');
// 调用用户头像简码
function do_shortcode_user_head($atts, $content = null) {
include('short_code/UserHead.php');// Php文件路径,就是之前创建的“'short_code”文件夹下面的文件“UserHead.php”
return '';
}
add_shortcode('user_head', 'do_shortcode_user_head');
do_shortcode_user_head就是下面add_shortcode(‘user_head’,要调用的简码名;[user_head]
3、在模板/文章/页面用这个代码[user_head]调用
总结截图:
1、
2、
3、