Simon.AU Posted May 25, 2022 Posted May 25, 2022 Hi all, I've successfully created a custom block containing some php which just echo's text to the page (as a simple test). But I get an error on save if I do anything other than wrap my custom php inside a function, like so: function myTest() { echo 'testing'; } How to I run my function? If I just include myTest() in the page source I get an error.
Marc Posted May 25, 2022 Posted May 25, 2022 If you are adding exactly what you put second there, you are missing a semicolon at the end.
Simon.AU Posted May 26, 2022 Author Posted May 26, 2022 Thanks Marc. Unfortunately I can no longer edit the original post but that was just my example. Can you please confirm for me how this is supposed to work, because I can't find it in the documentation. Is it a requirement that php code be encapsulated in a function, and then the function must be called (the only non-functionised code) from a single line as I have shown above (with semicolon)? I can't get anything to generate some output, even though the block editor is no longer balking at my php code.
Solution teraßyte Posted May 26, 2022 Solution Posted May 26, 2022 (edited) As long as the semicolon is there that code works just fine inside a custom PHP block. I just tested myself by copy pasting your code (adding the semicolon) in a block. Then I added the block to a page. Maybe you have more code in your block other than the one you posted in the first post?  And no, there is no need to even use a function. You can just input your PHP code inside the block without it. A custom PHP block with the code below prints the same output as your code above: echo 'testing'; Edited May 26, 2022 by teraßyte SeNioR- 1
Simon.AU Posted May 30, 2022 Author Posted May 30, 2022 I see thanks guys. I don't know what is going on with my cloud setup but this code wasn't working on Friday, and I refreshed today and it starts working. Must have been a cache issue somewhere, but thanks for the help.
Recommended Posts