Re is out: see what's new Lifetime updates on every purchase Support replies within 24 hours Secure checkout via Gumroad 8,500+ sales since 2016

↑↓ Navigate ↵ Open Esc Close

All products
Re:Maily contact form builder is now available on WordPress.org See it live

Theme functions

Updated 2 min read 12 views

These functions are the part of Forma a theme should call. They keep their names and arguments across versions, while the classes behind them may move.

FunctionReturnsUse it to
forma_render( $id, $args )HTMLPrint a layout as its shortcode does. $args: show (grid, filter, search, sort, pagination) and instance (which grid of the layout a control drives)
forma_layouts()[ ID => title ]List the published layouts, for a theme option or a page builder select
forma_get_template( $path, $vars )HTMLRender a template of templates/, the theme’s copy first, for example notices/empty.php
forma_item_part( $name, $item, $args )PrintsPrint a part of a card in skin.php: image, video, title, terms, tags, date, count, excerpt, or a part of the theme’s own
forma_icon( $name, $class )SVGPrint an icon of templates/icons/, the theme’s copy first
forma_link_start( $item, $class ) / forma_link_end( $item )HTMLOpen and close an item’s link in a card; it follows the layout’s Click action, and is a <div> when the item has no link
forma_is_built_in_style( $id, $kind )boolCheck whether a style ships with the plugin
forma_lightbox( $group, $image_id, $caption, $src )AttributesOpen an image in Forma’s lightbox; links of one group form one gallery. [] while the lightbox is off
forma_lightbox_media( $group, $url, $kind, $caption, $poster_id )AttributesThe same for a video or audio URL, when an add-on such as Pro plays it
forma_attributes( $attributes )StringPrint attributes, escaped, with a leading space
forma_is_pro()boolCheck whether Forma Pro runs

Example: a layout picker in the Customizer

add_action( 'customize_register', function ( $wp_customize ) {
	$wp_customize->add_setting( 'my_theme_home_grid', [ 'sanitize_callback' => 'absint' ] );
	$wp_customize->add_control( 'my_theme_home_grid', [
		'label'   => __( 'Home page grid', 'my-theme' ),
		'section' => 'static_front_page',
		'type'    => 'select',
		'choices' => [ 0 => __( 'None', 'my-theme' ) ] + forma_layouts(),
	] );
} );
// front-page.php
$grid = (int) get_theme_mod( 'my_theme_home_grid' );

if ( $grid ) {
	echo forma_render( $grid );
}

Example: your own images in Forma’s lightbox

<?php foreach ( $image_ids as $id ) : ?>
	<a href="<?php echo esc_url( wp_get_attachment_url( $id ) ); ?>"<?php echo forma_attributes( forma_lightbox( 'about-gallery', $id, get_the_title( $id ) ) ); ?>>
		<?php echo wp_get_attachment_image( $id, 'large' ); ?>
	</a>
<?php endforeach; ?>

The links share the group about-gallery, so they open as one gallery with arrows.

Was this article helpful?