skip to Main Content

Add Custom Dynamic Variables

The following snippet will show you how to add your own custom dynamic variables which can be used inside theme elements or certain theme settings. Please visit the dynamic variables documentation for more info.

/**
 * Add Custom Dynamic Variables.
 *
 * @link https://total.wpexplorer.com/docs/snippets/add-custom-dynamic-variables/
 * @since 5.6.1
 */
add_filter( 'wpex_replacement_vars', function( $vars ) {

    // Add a new static custom var.
    $vars['my_custom_var'] = 'test';

    // Add a new dynamic custom var.
    $vars['my_custom_var_dynamic'] = my_custom_var_dynamic_value();

    return $vars;
} );

/**
 * Custom Dynamic Variables Callback function.
 */
function my_custom_var_dynamic_value() {
    return 'Dynamic Value Test';
}
Back To Top