使用Wordpress中的短代码显示当天的营业时间

时间:2018-01-26 09:55:08

标签: php wordpress shortcode

我对PHP很陌生,但是我编写了这段代码,它抓住了当天的当天,显示了当天的开放时间。当我的WP站点的标题中包含这个时,它工作正常。

<?php
$openingHours = [
'Mon' => "Today we're open 8.30am – 6:30pm",
'Tue' => "Today we're open 8.30am – 6:30pm",
'Wed' => "Today we're open 8.30am – 6:30pm",
'Thu' => "Today we're open 8.30am – 6:30pm",
'Fri' => "Today we're open 8.30am - 6:30pm",
'Sat' => "Today we're open 8.30am – 3:00pm",
'Sun' => "Today we're closed"
];
$day_today = date('D');
?>
<div class="openingHours">
<?php echo $openingHours[$day_today];?>
</div> 

我想将它添加为wordpress中的短代码,这样我就可以将它放在页面的任何位置,但似乎无法让它完全起作用..

这就是我现在所拥有的:

function pet_hours () {
echo $openinghours[$day_today];
$day_today = date('D');
$openinghours = [
'Mon' => "Today we're open 8.30am – 6:30pm",
'Tue' => "Today we're open 8.30am – 6:30pm",
'Wed' => "Today we're open 8.30am – 6:30pm",
'Thu' => "Today we're open 8.30am – 6:30pm",
'Fri' => "Today we're open 8.30am - 6:30pm",
'Sat' => "Today we're open 8.30am – 3:00pm",
'Sun' => "We are closed today"];
}
add_shortcode( 'pet_hours' );

我哪里错了?

0 个答案:

没有答案