• Hi I have preloader plugin but they just changed how the tag is inserted, I tried both methods how do I allow the wp_body_open hook to work if it doesn’t exist?

    Insert preloader element manually.

    The preloader element is automatically added to your theme using the “wp_body_open” hook. However, if your theme doesn’t support this hook or doesn’t display the preloader correctly, enable this option, then go to your theme’s header.php file and add the following code right after the “<body>” tag:
    <?php echo the_preloader_element(); ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Gantry

    (@gantry)

    @jasonmac_75 thanks for the question. Here’s what I found – hopefully this is helpful to you:
    Unfortunately, Gantry 5’s theme system doesn’t include the wp_body_open() hook natively, because it builds the theme layout via Twig templates, not a traditional header.php file.

    Here is one possible solution but I have not tested it:

    Editing your theme’s index.php file:

    <?php if (function_exists('wp_body_open')) wp_body_open(); ?>

    Insert that right after the <body> tag. If your plugin supports inserting the preloader manually, you can also add:

    <?php if (function_exists('the_preloader_element')) echo the_preloader_element(); ?>

    Unfortunately, Gantry’s admin interface doesn’t allow inserting PHP after <body>, so this small file edit is required.

    If this doesn’t work I would continue debugging with your preferred AI (chatgpt etc). It has solved a lot of my problems.

    Thread Starter jasonmac_75

    (@jasonmac_75)

    Thanks for the help, I went down the chat gpt route, of adding: {{ function(‘do_action’, ‘wp_body_open’)|raw }} to the /wp-content/plugins/gantry5/engines/nucleus/templates/page.html.twig file is there anyway to do an override for this in-case of updates?

    ie tried this /wp-content/themes/g5_hydrogen/custom/templates/page.html.twig
    or /wp-content/themes/g5_hydrogen/custom/templates/nucleus/page.html.twig

    Many thanks Jason

    https://mac-designs.com/ shows live preloader, prefer this as when slider loading you always get slight shift or jump of the images when fitting to viewport.

    Plugin Author Gantry

    (@gantry)

    @jasonmac_75 nice – good work.

    Here a way to protect your override:

    The file:

    /wp-content/plugins/gantry5/engines/nucleus/templates/page.html.twig

    Should be overridden in your theme under:

    /wp-content/themes/g5_hydrogen/custom/nucleus/templates/page.html.twig

    ✅ Note the structure: /custom/nucleus/templates/ matches the engines/nucleus/templates/ path inside the plugin.

    Steps to safely override page.html.twig

    1. Create the override path if it doesn’t already exist: swiftCopyEdit/wp-content/themes/g5_hydrogen/custom/nucleus/templates/
    2. Copy the original file from the plugin: swiftCopyEdit/wp-content/plugins/gantry5/engines/nucleus/templates/page.html.twig to: swiftCopyEdit/wp-content/themes/g5_hydrogen/custom/nucleus/templates/page.html.twig
    3. Edit your copied file to include your modification: twigCopyEdit{{ function('do_action', 'wp_body_open')|raw }}
    4. Clear Gantry cache via the admin panel or delete the compiled folder inside: swiftCopyEdit/wp-content/themes/g5_hydrogen/

    Thread Starter jasonmac_75

    (@jasonmac_75)

    Thanks for your help unfortunately it wouldn’t update when I added the override folder/wp-content/themes/g5_hydrogen/custom/nucleus/templates/ so I’ve added to the main gantry file for the meantime.

    Could it be added to the to the main page.html.twig gantry file for the next update?

    Many thanks Jason

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Preloader and gantry’ is closed to new replies.