我只需要通过header.php在特定页面上添加自定义简码
这让我有些困惑, 因为我尝试仅将is_page()放在if()中, 但是它不起作用。我需要从代码中执行以下操作:
示例代码在这里:
$page = 'page_slug';
if (is_page($page)) {
do_shortcode('[shortcode]');
}
由于某种原因, 这是行不通的。
#1
你可以在if语句中执行get_page函数。即使将其评估为false, 该函数也会执行, 我敢肯定问题出在那。
考虑更改get_page以使其仅返回布尔值, 而不进行其他操作。
当然, 那么你可以只留下if语句并摆脱else。
编辑:这是一个例子。 else语句为空, 在执行该函数以确定是否应输入该语句时, 除了” bar”以外, 什么都不会打印。
#2
你不需要使用else, 因为你的代码不会返回或回显结果
$page = '4827';
if (get_page($page)) {
echo do_shortcode('[shortcode]');
}
来源:
https://www.srcmini02.com/63645.html
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37587.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57