NO BUG: {echo:my_custom_function} Fails

Browser: ARC Version 1.61.2 (54148)
OS: macOS Sanoma 14.6.1 (23G93)
URL: Localhost
Video: Short screen recording that illustrates this issue (free tool: jam.dev)

I tried to make it simple as I am trying to perform something more complex.

I followed the video for using “echo” to call a function and nothing is returned. All code is signed.

1 Like

Hey @jmcbade,

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?

Best,

André

It was the one used in the example for the video:

function my_custom_function() {

echo “Hello world!”;

}

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).

That does work.

Have to quote myself: did you whitelist the function? :sweat_smile:

And also: the function itself should not echo anything. Instead it should return the value:

function my_custom_function() {
  return 'Hello world!';
}

Best,

André

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.

Let us know :slight_smile:

Sorry, I did use “return”. I typed it off the top of my head as I went out the door tonight.

I also registered the function and I put it in the whitelist function.

// Custom Functions
add_filter( ‘bricks/code/echo_function_names’, function() {
return [
‘date’,
‘my_custom_function’,
];
} );

Hi,

can you tell us also where did you put this filter, and where did you put your custom function? In a child theme?

I put the filter in the child theme. I’ve tried the custom function in either the child theme or WP Codebox

Hi @jmcbade ,

Did you activate the Child theme?
Otherwise, please send admin credentials to help@bricksbuilder.io so we can investigate.

Regards,
Jenn

Yes I use a child theme.

This is on a localhost (MAMP)

Hi @jmcbade ,

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?

Regards,
Jenn

This video and link:

It seems I have to in these steps:

  • Create the function
  • 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.

Hey @jmcbade,

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.

Quick demonstration: Video uploaded to CleanShot Cloud.

Best,

André

1 Like

It’s the weekend here in Japan.

I will revisit this again on Monday.

Sincerely, thank you for the assistance.

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.

1 Like