Skip to content

Example: Edit Shortcuts

Jörn Lund edited this page Oct 27, 2018 · 2 revisions

Adding an edit shortcut to the themes HTML output can be achieved by calling one of the acf_customizer_field, acf_customizer_row or acf_customizer_sub_field actions.

Single fields

Let‘s assume you output some field somewhere in your theme.

the_field( 'some_field' );

The same with an edit shortcut added:

do_action( 'acf_customizer_field', 'some_field' );
the_field( 'some_field' );

Outside the Loop you need to pas the post id too:

do_action( 'acf_customizer_field', 'some_field', 123 );
the_field( 'some_field', 123 );

Repeater Loops

Inside a repeater or layout field:

while ( have_rows('repeatable_field') ) {
    the_row();
    // This will create a shortcut to the entire repeater
    do_action( 'acf_customizer_row' );

    the_sub_field('repeated_field');
    // That on creates a shortcut directly to the input of 'repeated_field'
    do_action( 'acf_customizer_sub_field', 'repeated_field' );
}
Clone this wiki locally