Layotter Documentation

Show menu

Settings filters

Settings filters can be used to configure all of Layotter's settings programmatically. While there is a graphical settings page that can be used for quick and easy configuration, there are two good reasons to use settings filters instead:

  1. In some cases, filters allow for customization that isn't possible using the settings page.
  2. Configuration using settings filters can be easily migrated to a different site by simply copying the PHP code.

layotter/enabled_post_types

Define the post types you want to use Layotter with.

The filter function receives an array of post types for which Layotter is currently enabled (as defined on the settings page) and should return the modified array.

function custom_enabled_post_types($post_types) {
    $post_types[] = 'page';
    return $post_types;
}

add_filter('layotter/enabled_post_types', 'custom_enabled_post_types');

layotter/enable_for_posts and layotter/disable_for_posts

Enable or disable Layotter for particular posts (overriding enabled post types).

These filter functions receive and return an array of post IDs to enable (or disable) Layotter for.

layotter/enable_for_posts takes precedence over layotter/disable_for_posts, i.e. putting the same ID in both will result in Layotter being enabled for that post.

function custom_enabled_posts($post_ids) {
    // enable Layotter for the static front page only
    $post_ids[] = get_option('page_on_front');
    return $post_ids;
}

add_filter('layotter/enable_for_posts', 'custom_enabled_posts');

layotter/enable_post_layouts

Enable or disable the post layouts feature.

The filter function receives the current setting (as defined on the settings page) and should return true or false.

function custom_enable_post_layouts($current_setting) {
    return true;
}

add_filter('layotter/enable_post_layouts', 'custom_enable_post_layouts');

layotter/enable_element_templates

Enable or disable the element templates feature.

The filter function receives the current setting (as defined on the settings page) and should return true or false.

function custom_enable_element_templates($current_setting) {
    return true;
}

add_filter('layotter/enable_element_templates', 'custom_enable_element_templates');

layotter/enable_default_css

Enable or disable default CSS styles for rows and columns that allow you to get started out of the box, but might get annoying once you start adding your own custom styles.

The filter function receives the current setting (as defined on the settings page) and should return true or false.

function custom_enable_default_css($current_setting) {
    return true;
}

add_filter('layotter/enable_default_css', 'custom_enable_default_css');

layotter/enable_example_element

Enable or disable the example element type that allows you to play around with Layotter and get started quickly.

The filter function receives the current setting (as defined on the settings page) and should return true or false.

function custom_enable_example_element($current_setting) {
    return true;
}

add_filter('layotter/enable_example_element', 'custom_enable_example_element');

layotter/rows/allowed_layouts

Define a set of row layouts that can be selected in the drag and drop editor.

The filter function receives an array of allowed row layouts (as defined on the settings page) and should return the modified array.

function custom_allowed_row_layouts($row_layouts) {
    $row_layouts[] = '1/2 1/2';
    $row_layouts[] = '1/3 1/3 1/3';
    $row_layouts[] = '1/4 3/4';
    return $row_layouts;
}

add_filter('layotter/rows/allowed_layouts', 'custom_allowed_row_layouts');

As shown above, row layouts are simply strings containing a number of fractions separated by spaces. 1/3 1/3 1/3 for instance means that rows with three equally wide columns can be created. Column sizes can be combined freely, as long as they add up to one.

These column widths are available for combination: 1/1, 1/2, 1/3, 1/4, 1/6, 2/3, 3/4, 5/6, 1/12, 5/12, 7/12 and 11/12.

It's your responsibility to make sure that the column sizes add up to one.

Always cancel down fractions! 6/12 will not work, but 1/2 will.

layotter/rows/default_layout

Define a default layout for newly created rows.

The filter function receives a string with the current default layout (as defined on the settings page) and should return the modified string.

function custom_default_row_layout($current_setting) {
    return '1/3 1/3 1/3';
}

add_filter('layotter/rows/default_layout', 'custom_default_row_layout');

See layotter/rows/allowed_layouts above for details on how to format row layouts.

layotter/columns/classes

Define CSS classes for all column types. These classes will be applied to each column in the frontend view.

The filter function receives an array with column widths and their corresponding CSS classes (as defined on the settings page) and should return the modified array.

function custom_column_classes($column_classes) {
    $column_classes['1/3'] = 'column one-third';
    $column_classes['3/4'] = 'column three-fourths';
    return $column_classes;
}

add_filter('layotter/columns/classes', 'custom_column_classes');

layotter/debug_mode_roles

Define roles for which debug mode should be enabled. In debug mode, you can inspect and manually modify Layotter's internal JSON data structure when editing a post.

The filter function receives an array with roles for which debug mode is enabled (as defined on the settings page) and should return the modified array.

function custom_debug_mode_roles($roles) {
    $roles[] = 'administrator';
    return $roles;
}

add_filter('layotter/debug_mode_roles', 'custom_debug_mode_roles');