it would help a lot to see your function and to know where exactly you are trying to call that function (on a static page? in a template? within a loop?). Did you whitelist the function to be used with the echo tag as described here?
The only thing I can get working it to write my code in a snipit or snipit manager (or functions.php) and then call the function inside a code block (Bricks code element).
Yep, looks like you did not whitelist the my_custom_function. Please check this, and in the function, instead of “echo”, do a return, just like @aslotta suggested.
We won’t be able to assist if we can’t access your site.
Using {echo:} with any element is quite straightforward.
Here’s a tested solution: Place the following code in your child theme’s functions.php file (make sure the child theme is activated). Also, note that if you’ve used this filter in multiple places, the filter results might get overwritten depending on the priority parameter.
add_filter( 'bricks/code/echo_function_names', function() {
return [
'my_custom_function',
];
} );
function my_custom_function() {
return 'Hello from my custom function';
}
Then, use {echo:my_custom_function} on a Basic Text element. You should see “Hello from my custom function” displayed. If it doesn’t render in the builder, make sure the “Render dynamic data text on canvas” option is enabled.
I followed the video for using “echo” to call a function and nothing is returned. All code is signed.
Could you also share the URL of the video you’re referring to?
Place the {echo:my_custom_function} in an element (Text)
Run it and let it fail
Go to settings and do the code review
Go back and ass the new echo for the function name in the filter
Sign the code
Save
And then it seems to work. Feels like a LOT of steps to get right to make this work, but I now get it to work sometimes with very simple functions only.
I’m trying to see where it it failing sometimes and not others - to find just what step I am missing.
there is no code signing involved when using the dynamic echo tag. All you have to do is whitelist the function as mentioned above. The order also shouldn’t matter at all.
Well, so far following your kind advice, my functions are working and the data is presenting as expected. I’m definitely doing things more complex than “Hello world!”
I am even using WP Codebox for the code.
Again, thank you everyone for the effort and time to assist.