Cyber Monday Sale! Save up to 50% now.

View API

Make uses “views” to determine which layout settings to apply to a given page load.

A view definition consists of a view ID that corresponds to an array of properties. The required properties for a view are a label and a callback function that determines whether it qualifies to be the current view. A third, optional property is priority, which determines which view will take precedent when the current view qualifies for multiple views. A higher priority will take precedent over a lower.


Example: Add views for a “tea” custom post type

function childtheme_add_tea_views() {
	make_update_view_definition(
		'tea',
		array(
			'label'    => __( 'Tea', 'make-child' ),
			'callback' => 'childtheme_is_tea',
			'priority' => 20
		)
	);

	make_update_view_definition(
		'tea-menu',
		array(
			'label'    => __( 'Tea Menu', 'make-child' ),
			'callback' => 'childtheme_is_tea_menu',
			'priority' => 20
		)
	);
}

add_action( 'make_view_loaded', 'childtheme_add_tea_views' );

In the above example, the make_update_view_definition() function takes two parameters. The first is a unique ID for the view. The second is an associative array of view properties. The required properties are a public label and a callback function that determines whether it qualifies to be the current view. A third, optional property is priority, which determines which view will take precedent when the current view qualifies for multiple views. A higher priority will take precedent over a lower.

The callback functions from the above example might look something like this:

function childtheme_is_tea() {
	return is_singular( 'tea' );
}

function childtheme_is_tea_menu() {
	return is_post_type_archive( 'tea' );
}