Last active
February 22, 2025 07:33
-
-
Save abdullahwp/e4aa599c3896c864d0f4a83b6e4d8392 to your computer and use it in GitHub Desktop.
jetengine register macro for current day of the week for wordpress timezone
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 characters
| add_action( 'jet-engine/register-macros', function() { | |
| class Custom_Weekday_Macro extends \Jet_Engine_Base_Macros { | |
| /** | |
| * Macros tag - this macro will look like %custom_weekday% | |
| */ | |
| public function macros_tag() { | |
| return 'custom_weekday'; | |
| } | |
| /** | |
| * Macros name in UI | |
| */ | |
| public function macros_name() { | |
| return 'Custom Weekday (WordPress Timezone)'; | |
| } | |
| /** | |
| * Macros arguments - no arguments are needed for this macro | |
| */ | |
| public function macros_args() { | |
| return array(); | |
| } | |
| /** | |
| * Macros callback - returns the current day of the week based on WordPress timezone | |
| */ | |
| public function macros_callback( $args = array() ) { | |
| // Get the current timestamp in WordPress timezone | |
| $timestamp = current_time( 'timestamp' ); | |
| // Return the localized day of the week | |
| return date_i18n( 'l', $timestamp ); // 'l' for full weekday name | |
| } | |
| } | |
| // Register the macro | |
| new Custom_Weekday_Macro(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment