How to add a custom location for inserting sections in your theme with Nimble Builder

Note : This documentations assumes that you have a minimal knowledge of PHP and WordPress customization. In particular how to work with child themes in WordPress.

The Nimble Builder includes 4 predefined locations for your sections :

  1. loop_start
  2. before the_content
  3. after the_content
  4. loop_end

But the plugin includes a developer API allowing you to easily add custom locations. This can be useful for example if you need to add a custom location in the header of the footer of a particular page. Or even a site wide location to display a set of sections on every pages.


In the following example, we use a child theme of the Twenty Nineteen theme. But this can be done with any WordPress theme. 

We will add a location to the header of the theme, and share a screenshot of how this new location looks like when customizing.

Registering a new location

in the functions.php file of your child theme, add the following code :

// Register a custom location for the Nimble Builder Plugin
// ( always check if function_exists so the theme won't break when Nimble Builder is deactivated )
if ( function_exists('nimble_register_location') ) {
    nimble_register_location('my_nimble_header_location');
}

You can of course replace the custom location name, 'my_nimble_header_location', by any name.

Hooking this location in a template's file of your theme

In this example, we want to add a location in the header. So in the child theme's folder, create a header.php file, which should be a copy of the parent theme header.php. And insert the following code in the template, where you want your Nimble sections to be displayed :

<?php do_action('my_nimble_header_location'); ?>

You're done.

Now when you'll open the live customizer, you'll see a new drop zone location in your header like in the screenshot below : 

Adding a custom location with the Nimble Builder

How to add a global location for your sections, displayed site wide ?

If you want the sections of this location to be displayed site wide, simply add the parameter array( 'is_global_location' => true ) to the registration function.

// Register a custom location for the Nimble Builder Plugin
// ( always check if function_exists so the theme won't break when Nimble Builder is deactivated )
if ( function_exists('nimble_register_location') ) {
    nimble_register_location('my_nimble_header_location', array( 'is_global_location' => true ) );
}
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.