Skip to main content

[WP] Adding custom {{variables}} to Slide Markup Editor

This tutorial requires PHP knowledge!

Use new_rs_slides_renderer_helper filter to add custom variables to Slide Markup Editor, for example to add variable {{hello_world}}:

function newrs_add_custom_variables($m, $data, $options) {
$m->addHelper('hello_world', function() {
return 'Hello world!';
} );
}
add_filter('new_rs_slides_renderer_helper', 'newrs_add_custom_variables', 10, 4);

More info about syntax in mustace.php documentation.

Example, get ACF field value for "Posts" slider:

The code below will create a variable, called {{test_variable}}, which will return the value of the custom field with field-name test. ACF get_field documentation http://www.advancedcustomfields.com/resources/get_field/

function newrs_add_acf_variable($m, $data, $options) {

$m->addHelper('test_variable', function() use ($data) {

// $data is a WordPress post object (for posts-slider)

// just return value
return get_field( "test", $data->ID ) ;
} );

}
add_filter('new_rs_slides_renderer_helper','newrs_add_acf_variable', 10, 4);

Example, get ALT attribute of image in "Custom" slider

Creates {{alt_custom}} variable that returns alt field of media library image object.

function newrs_add_custom_alt_variable($m, $data, $options) {
$m->addHelper('alt_custom', function() use ($data) {
// $data object holds all data about slide
if(isset($data['image']) && isset($data['image']['attachment_id'])) {
$attachment_id = $data['image']['attachment_id'];
return get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
}
return '';
} );
}
add_filter('new_rs_slides_renderer_helper','newrs_add_custom_alt_variable', 10, 4);