Archived topic
Include .php in a block inside sidebar
5 replies · Started by mistergubu on January 10, 2022
Hello,
I want to include a .php file with content (Ads) "in the middle" of the left sidebar, inside a block. How can I do it? I can't find any block container where I can add php code.
My left sidebar sould have this scheme:
-Search Box
-Ads (.php include)
-Categories box
Thanks
Hi there,
you can't add PHP inside a block. You would need to have a shortcode to run your PHP function or create your own custom block.
ok thanks, I understand now, I did it with a shorcode that run a function,
but can you give a basic example about how to create my custom block to run php code?
Hi there,
You'll have to write your PHP into a shortcode and use that shortcode in a Shortcode block on your sidebar.
Here's a basic sample of making a shortcode - https://docs.generatepress.com/article/creating-a-shortcode/
The codes to make a shortcode is PHP so here's how to add PHP snippets to the site - https://docs.generatepress.com/article/adding-php/
ok thanks,
everything resolved.
Thank you for letting us know. Glad you got it sorted. :D