admin管理员组文章数量:1123884
I'm trying to use the below code to show a button on Sunday mornings, but I dont want to use "date_default_timezone_set()" because it rewrites the Wordpress date and then the events show the wrong time.
Is there a way to make this code work with the existing Wordpress date settings? When I remove "date_default_timezone_set();" the time goes back to UTC (4 hours ahead) even though Wordpress is set to New York (-4 UTC). Wondering if I need to place this code somewhere other than the header.php...
(I'm a PHP novice.)
<?php
date_default_timezone_set('America/New_York');
$currentDay = date("w");
$currentHour = date("H");
$openTime = 10; // 10 = 10am
$closeTime = 12; // 12 = 12pm
$serviceDay = 0; // 0 = Sunday
if ($currentHour >= $openTime && $currentHour < $closeTime && $currentDay == $serviceDay){
$css = 'timeOn';
} else {
$css = 'timeOff';
} ?>
HTML & CSS
<a class="<?php echo $css; ?>" href="#">
<div class="liveService"><?php echo 'WATCH LIVE'; ?> </div>
</a>
.timeOn {display:block;}
.timeOff {display:none; }
Code from:
本文标签: phpShow Element at Certain Time in Wordpress
版权声明:本文标题:php - Show Element at Certain Time in Wordpress 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736605820a1945325.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论