php包含在wordpress模板中的短代码

时间:2013-11-15 09:11:29

标签: php wordpress conditional shortcode

我正在使用wordpress插件输出一个取决于国家/地区代码的php include,我已经设置了依赖于位置输出文本的条件短代码,但不能将其提升到下一级别一个php文件:

<? echo do_shortcode('[wpgc_is_country_code country_code="UK"]' . 'hello' .'[/wpgc_is_country_code]');?>

这输出“你好”,但我希望它包含一个php文件。我试过这个:

<? echo do_shortcode('[wpgc_is_country_code country_code="UK"]' . 'include('include/UK.php')' .'[/wpgc_is_country_code]');?>

但它不起作用,输出是空白的,我在“包含”部分出错了哪里? (我也尝试过使用“get_template_part”功能而没有运气)

提前感谢!

1 个答案:

答案 0 :(得分:0)

hello是一个字符串,所以必须有引号但include是一个函数,在include()中删除单引号中的任何函数是错误的,并试试这个

<? echo do_shortcode('[wpgc_is_country_code country_code="UK"]' . include('include/UK.php') .'[/wpgc_is_country_code]');?>