Does Not Work With Shortcodes
-
Good Day,
Unfortunately, your plugin does not work with shortcodes (not ours, at least). We read all support topics in this forum related to shortcodes and applied all of your recommended solutions. None of them work.
This particular support topic describes exactly what we’re running into.
So, per your topic request, we would like to see if you can make your plugin work for the exercise given below.
Our environment: PHP 8.3.8, jQuery 3.7.1, Avada 7.11.9, WP 6.5.5
Our caching mechanisms: Speed Optimizer (plugin) and Cloudflare.
Fix appreciated. Your plugin has a lot of potential.
Thank you!
—————-
Exercise:
- Add the code snippet provided below to your functions.php file (we’re using the plugin Code Snippets for this purpose). The code snippet generates the shortcode [business_hours]. Note: We used two versions of the code snippet provided below — one with and the other without the conditional
if (is_page ('contact'))
- Add the shortcode [business_hours] to your “Edit non-cachable content” post (details).
- Using the shortcode generated by your plugin [content_no_cache id=”nnnnnn”], add it to your site content (details).
- Results: https://prnt.sc/Ep71Azj7RE1g
———————-
Code Snippet for Shortcode [business_hours]:
function business_hours_shortcode($atts) {
if (is_page ('contact')) {
// Set timezone - change this to match your own.
date_default_timezone_set('America/Chicago');
// An array of your opening hours.
$opening_hours = array(
'Monday' => array('07:30', '17:30'),
'Tuesday' => array('07:30', '17:30'),
'Wednesday' => array('07:30', '17:30'),
'Thursday' => array('07:30', '17:30'),
'Friday' => array('07:30', '17:30'),
'Saturday' => array('Closed'),
'Sunday' => array('Closed'),
);
// An array of your holidays (format: month/day - add zero before single-digit month or day)
$holidays = array('01/01', '05/26', '07/04', '07/05', '09/02', '11/11', '11/28', '11/29', '12/24', '12/25', '12/31');
// Get current date, day, and time.
$current_date = date('m/d');
$current_day = date('l');
$current_time = date('H:i');
// Get today's opening hours.
$today_hours = $opening_hours[$current_day];
// Check if today is a holiday.
if (in_array($current_date,$holidays)) {
return '<span style="font-weight:600;color:#ffffff;background-color:#e14d43;padding:6px 12px;border-radius:3px;">CLOSED FOR THE HOLIDAY</span>';
}
// Check if we have opening hours for today.
if (!isset($today_hours) || count($today_hours) < 2) {
return '<span style="font-weight:600;color:#ffffff;background-color:#e14d43;padding:6px 12px;border-radius:3px;">CLOSED TODAY</span>';
}
// Check if current time is between opening hours.
if ($current_time >= $today_hours[0] && $current_time <= $today_hours[1]) {
return '<span style="font-weight:600;color:#ffffff;background-color:#00c853;padding:6px 12px;border-radius:3px;">CURRENTLY OPEN</span>';
} else {
return '<span style="font-weight:600;color:#ffffff;background-color:#e14d43;padding:6px 12px;border-radius:3px;">CURRENTLY CLOSED</span>';
}
}
}
add_shortcode('business_hours', 'business_hours_shortcode'); - Add the code snippet provided below to your functions.php file (we’re using the plugin Code Snippets for this purpose). The code snippet generates the shortcode [business_hours]. Note: We used two versions of the code snippet provided below — one with and the other without the conditional
- The topic ‘Does Not Work With Shortcodes’ is closed to new replies.