Skip to content

Snippet: 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
 * @since 5.6.1
add_filter( 'totaltheme/replace_vars/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';
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top