[Support request] Inserting custom PHP/HTML into gutenberg or site “container”?

Home Forums Support [Support request] Inserting custom PHP/HTML into gutenberg or site “container”?

Home Forums Support Inserting custom PHP/HTML into gutenberg or site “container”?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1713259
    Thomas

    Hello everyone and thank you for the help.

    I coded a small contact form in PHP and inserted it utilizing Hooks and elements with GeneratePress. It works, however the only “issue” i have is that that content isn’t contained within the sites container. I know this could be fixed utilizing CSS, but i’d like to make it as “hands off” as possible for the end admins of the site. So i’m wondering if there’s a way to create custom blocks for gutenberg utilizing GeneratePress, or some kind of method i’m missing that this could be apart of?

    Also a quick side question; in terms of GeneratePress it’s better to “code a theme” utilizing elements then directly into a child theme or is there even much of a difference?

    edit: Actually my logic isn’t working by doing it this way…I guess i’d have to develop a plugin for it?
    Thank you so much!

    #1713328
    Leo
    Staff
    Customer Support

    Hi there,

    So i’m wondering if there’s a way to create custom blocks for gutenberg utilizing GeneratePress, or some kind of method i’m missing that this could be apart of?

    It would definitely require some custom coding to create your own custom blocks and I’m not sure if it’s worth the effort.

    The contact page is set to full width in content container which is why the content isn’t within the container:
    https://docs.generatepress.com/article/content-container/

    I feel like the best solution here is to use a plugin like Contact form 7 instead of creating your own.

    #1713330
    Thomas

    Yeah I guess sometimes its not worth going out the way to hand code stuff when something like CF7 would work just as well lol!

    Thanks Leo.

    #1713422
    Elvin
    Staff
    Customer Support

    Hi there,

    If I may, let me share a bit of food for thought:

    There’s actually a way to insert custom PHP within gutenberg.

    You can create a custom shortcode that allows you to create a portable hook you can place anywhere within the Gutenberg Editor.

    We then create a shortcode to allow us to create portable hooks anywhere it’s placed.

    add_shortcode('portable_hook', function($atts){
    	ob_start();
            $atts = shortcode_atts( array(
                'hook_name' => 'no foo'
            ), $atts, 'portable_hook' );
    		do_action($atts['hook_name']);
    	return ob_get_clean();
    });

    Usage: [portable_hook hook_name="my_custom_hook"]

    You can use this shortcode within the Block Editor.

    With this, we can utilize GP Premium’s Hook Element (for custom PHP) and hook them to our portable hook, in this example, my_custom_hook.

    But yeah, for your specific purpose, the best way is to just place a contact form block directly using plugins. 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.