【发布时间】:2017-01-22 20:23:28
【问题描述】:
请告诉我我在这里做错了什么... PHP 版本 5.6.27 使用 wordpress 4.7.1。我将其创建为自定义插件。我的页面将结果返回为“失败”,尝试了 2 个不同的页面标题并且都返回“失败”,这告诉我它没有在函数中获取页面标题(位置)并且函数返回 else 失败。
$locations = array(
array(
'location' => 'About',
'telephone' => '0121 34838383',
'email' => 'example@example.com'
)
);
function telephone_shortcode() {
global $locations;
$title = get_the_title();
$key = array_search($title, array_column($locations, 'location'));
if ($key)
return $locations[$key]['telephone'];
else
return 'fail';
}
add_shortcode('telephone', 'telephone_shortcode');
[电话] - 返回“失败”
【问题讨论】: