Register Helper in functions.php
-
Hello i trying to register a custom helper to detect if mobile or not, i have this code in functions.php
function is_mobile_handlebars_helper ( $handlebars,$options = null ) { // date_i18n. // {{my_test_helper 'test value'}}. $handlebars->registerHelper( 'is_mobile', function($options = null) { if (preg_match('/(Android|Maemo|iPhone|iPad)/i', $_SERVER['HTTP_USER_AGENT'])) { return $options['fn'](); } else { return $options['inverse'](); } } ); } add_action( 'lzb_handlebars_object', 'is_mobile_handlebars_helper' );
but is dosen’t work, however this code in the file class-block (inside the plugin)
//custom helpers $this->handlebars->registerHelper( 'is_mobile', function($options = null) { if (preg_match('/(Android|Maemo|iPhone|iPad)/i', $_SERVER['HTTP_USER_AGENT'])) { return $options['fn'](); } else { return $options['inverse'](); } } );
Work wonderfully, the question is how to fix the code in functions.php to avoid editing core plugin files
Thank you
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Register Helper in functions.php’ is closed to new replies.