Hooks/Filter Reference/builder filter current layout

From IThemes Codex
Jump to: navigation, search

Contents

Description

This filter hook is called in the Builder core after deciding which layout should be used. It passes a string with the selected layout ID. It is possible for the passed value to be an empty string, which would happen if the default layout is to be used.


Possible Uses

If your code needs to make a forced layout change based upon any type of possible criteria, this is the filter for you.


Parameters

$layout_id
(string) (required) The selected layout's ID.
Default: The current view's layout ID or if default is to be used.


Return Value

Returning a valid layout ID will result in that layout being used for the layout rendering. Returning an invalid layout ID will result in the default layout being used.

$layout_id
(string) (required) The desired layout ID.
Default: None


Examples

The following could be added to a child theme's functions.php file to allow the layout to be requested in the URL by supplying the layout ID as the value of a query variable called layout_id. For example: http://domain.com/?layout_id=4caf1cd049a69.

Note: Layout IDs can be found by hovering over the "Edit" link for a specific layout in the Layout editor. The end of the link will contain that layout's ID. Another way is to look at the ID attribute of the body class for a specific layout. The body ID will have the format of "builder-layout-[ID]".

function custom_builder_set_requested_layout_id( $layout_id ) { 
    if ( ! empty( $_GET['layout_id'] ) && is_string( $_GET['layout_id'] ) ) 
        return $_GET['layout_id'];
    return $layout_id;
}
add_filter( 'builder_filter_current_layout', 'custom_builder_set_requested_layout_id' );

Back to Builder Hooks

Personal tools
Namespaces
Variants
Actions
iThemes Codex
Codex Navigation
Toolbox