How do I move, hide or control the display of Mesh Sections

By default Mesh sections will automatically utilize the_content filter in order to place Mesh content directly after your page/post’s content. Within version 1.1 we added a powerful filter to disable automatic output of mesh sections after the loop. This is useful if you want to override the default functionality and place Mesh sections within your template but separate from “The Loop”.

Selectively Display Mesh Sections

In the example below we will hide Mesh sections on our home page but allow sections to be displayed everywhere else where Mesh is enabled.

add_filter( 'mesh_loop_end', 'hatch_mesh_loop_end' );

function hatch_mesh_loop_end( $sections ) {
    if ( is_home() ) {
        return '';
    } else {
        return $sections;
    }
}

Hide Mesh Sections Everywhere

Sometimes it’s more useful to hide Mesh everywhere and insert your sections yourself. If you want to hide Mesh sections from automatically displaying on all pages you can do the following.

add_filter( 'mesh_loop_end', '__return_empty_string' );

Just let me move Mesh section where every I want

Using mesh_loop_end in the example above we can stop the default output of Mesh sections and place the content anywhere in your template using and mesh_display_section(). Below is an example of practice in action.

Using the example above let’s hide our mesh sections.

add_filter( 'mesh_loop_end', '__return_empty_string' );

Now we can add in the following snippet within any of our theme template files (frontpage.php, page.php etc). The snippet itself will automatically echo out the Mesh sections associated with your page/post’s content.

if ( function_exists( 'mesh_display_sections' ) ) {
    mesh_display_sections();
}

Just be mindful that different post types can potentially have different templates (Ex: page.php vs single.php) or completely custom templates. If you fully remove Mesh sections everywhere using the filter above, be sure to add them back in as needed with mesh_display_sections().