Theme functions
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.
| Function | Returns | Use it to |
|---|---|---|
forma_render( $id, $args ) | HTML | Print 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 ) | HTML | Render a template of templates/, the theme’s copy first, for example notices/empty.php |
forma_item_part( $name, $item, $args ) | Prints | Print 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 ) | SVG | Print an icon of templates/icons/, the theme’s copy first |
forma_link_start( $item, $class ) / forma_link_end( $item ) | HTML | Open 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 ) | bool | Check whether a style ships with the plugin |
forma_lightbox( $group, $image_id, $caption, $src ) | Attributes | Open 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 ) | Attributes | The same for a video or audio URL, when an add-on such as Pro plays it |
forma_attributes( $attributes ) | String | Print attributes, escaped, with a leading space |
forma_is_pro() | bool | Check 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?
Thanks for your feedback!