Created
December 16, 2024 17:11
-
-
Save nathaningram/2bce69bd359f5d1ced731475ff4ad7af to your computer and use it in GitHub Desktop.
Revisions
-
nathaningram created this gist
Dec 16, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ ////////////////////////////////////////////////////////////////////////////// // Dynamic Copyright Date Based on Start Date and Biz Name // Usage: [bww-copyright] ////////////////////////////////////////////////////////////////////////////// // Shortcode to render a dynamic copyright statement function bww_copyright_shortcode() { // Retrieve the start year and business name from the Meta Box custom fields $all_options = get_option('site-info'); $start_year = $all_options['bww_info_start_date'] ?? ''; $business_name = $all_options['bww_info_business_name'] ?? ''; // Validate business name if (empty($business_name)) { $business_name = __('Your Business Name', 'bww_copyright'); // Default fallback } // Validate start year $output_start_year = ''; if (!empty($start_year) && is_numeric($start_year) && strlen($start_year) === 4) { $output_start_year = (int)$start_year; } // Current year $current_year = date('Y'); // Generate the copyright statement $copyright = '© Copyright '; $copyright .= $output_start_year ? $output_start_year . '-' : ''; $copyright .= $current_year . ' '; $copyright .= esc_html($business_name) . '. All Rights Reserved.'; return $copyright; } // Register the shortcode add_shortcode('bww-copyright', 'bww_copyright_shortcode');