Forked from Crocoblock/jet-engine-macros-shortcode.php
Created
March 2, 2025 16:12
-
-
Save Mohsin-Shakeel/ee6e211933bb2d2417b42f8fbf5e0263 to your computer and use it in GitHub Desktop.
Register [jet_engine_macros] shortcode to use JetEngine macros anywhere
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
<?php | |
/** | |
* How to use: | |
* 1. Add this code to your website with any code snippets plugin or into functions.php of your active theme. | |
* 2. In your admin area go to JetEngine/Macros Generator, generate and copy macros you need. | |
* 3. Use this macros anywhere with shortcode in following format: [jet_engine_macros macros="%generated_macros%"] | |
* | |
* Real world example: | |
* [jet_engine_macros macros="%jet_engine_field_name|event_date|field_value%"] | |
*/ | |
add_shortcode( 'jet_engine_macros', 'jet_engine_macros_shortcode' ); | |
/** | |
* Shortcode callback function. | |
* Based on this example, you can write your own function to call macros anywhere. | |
*/ | |
function jet_engine_macros_shortcode( $atts = [] ) { | |
$macros = ! empty( $atts['macros'] ) ? $atts['macros'] : false; | |
if ( ! $macros || ! function_exists( 'jet_engine' ) ) { | |
return; | |
} | |
return jet_engine()->listings->macros->do_macros( $macros ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment