Can't get information from Code element?

I’m trying to learn how to use PHP to retrieve information as dynamic data and I’m stuck trying to get it to output literally anything.

function zgf_test(){
	return 'test';
}

This is the only code I am trying to get to work. I don’t usually work in PHP so maybe the syntax is wrong or something? The Function names code review is also saying the function doesn’t exist?

image

Not sure what I’m missing but it’s just plain not working- saving and viewing the page, the area is just blank. No text

image

Hi @notMateo .

The {echo:zgf_test} may not be working because it might be running before the Code element is loaded or because the Code element doesn’t exist on that page.

Could you let me know where the Code element is located? Is it on a specific page?

For best practice, consider placing the zgf_test function in your child theme, so it’s accessible on any page.

Oh okay! That makes sense. It’s currently just one element above the header that’s using it. Should I place it at the top of the hierarchy? I’d rather use code element if possible at least to test, since it would be faster to iterate on.

Yes, you can place it on top of your structure and set “Don’t render wrapper” to not interrupt your HTML structure.

Just a note:
If the function will be used on a Query loop, it won’t work even if you place your code element at the top of the hierarchy. That is because Query loop will be executed far before render the elements.

Yeah I’m stilling having issues with it- I even placed it in functions.php of the child theme and it’s still not showing up on the page. Not sure what I’m doing wrong…

Hi @notMateo ,

Can you check if you have enabled Render dynamic data text on Canvas?

Bricks > Settings > Builder > Dynamic Data

Yeah it’s been on :+1:

Please reach us via email and provide admin access to find out the root cause.

Regards,
Jenn