Title: Advanced Custom Fields: Snippets
Author: tomekthewo
Published: <strong>8. juni 2019</strong>
Last modified: 8. juni 2019

---

Søk gjennom innstikk

Dette innstikket **er ikkje testa med dei tre siste utgåvene av WordPress**. Det
kan henda det ikkje blir vedlikehalde lenger, og kan ha problem med nyare versjonar
av WordPress.

![](https://ps.w.org/acf-snippets/assets/icon-256x256.png?rev=2102604)

# Advanced Custom Fields: Snippets

 Av [tomekthewo](https://profiles.wordpress.org/tomekthewo/)

[Last ned](https://downloads.wordpress.org/plugin/acf-snippets.zip)

 * [Detaljar](https://nn.wordpress.org/plugins/acf-snippets/#description)
 * [Omtalar](https://nn.wordpress.org/plugins/acf-snippets/#reviews)
 * [Utvikling](https://nn.wordpress.org/plugins/acf-snippets/#developers)

 [Hjelp](https://wordpress.org/support/plugin/acf-snippets/)

## Skildring

Adds useful functions for rendering image fields, link fields, repeater fields and
flexible content for the Advanced Custom Fields plugin. For [detailed info look on Bitbucket](https://bitbucket.org/tomekthewo/advanced-custom-fields-snippets/src/master/).

### Main advantages

 * write less code (do not repet same blocks of the code when writing down ACF custom
   fields)
 * built-in filters
 * works also for Gutenberg ACF Blocks
 * no init hooks etc (no impact on performance)

**Usage**

#### Link

Returns the snippet of a specific link field.

    ```
    <?php
        acf_snippet_get_link($selector, [$postId], [$args]);
    ?>
    ```

Displays the snippet of a specific link field.

    ```
    <?php
        acf_snippet_the_link($selector, [$postId], [$args]);
    ?>
    ```

**Parameters**
 $selector _(string) (Required)_ ACF field name or ACF field key.
Based on [ACF get_field function](https://www.advancedcustomfields.com/resources/get_field/).
$postId _(integer|bool) (Optional)_ The post ID where the value is saved. Use `true`
for getting sub field. Default value: `false` (current post). $args _(array) (Optional)_
Array of link output arguments. Default value: `null`.     **«class»** _(string)_`
class` attribute of the anchor.     **«id»** _(string)_ `id` attribute of the anchor.**«
title»** _(string)_ `title` attribute text of the anchor.

#### Image

Returns the snippet of a specific image field.

    ```
    <?php
        acf_snippet_get_image($selector, [$postId], [$args]);
    ?>
    ```

Displays the snippet of a specific image field.

    ```
    <?php
        acf_snippet_the_image($selector, [$postId], [$args]);
    ?>
    ```

**Parameters**
 $selector _(string) (Required)_ ACF field name or ACF field key.
Based on [ACF get_field function](https://www.advancedcustomfields.com/resources/get_field/).
$postId _(integer|bool) (Optional)_ The post ID where the value is saved. Use `true`
for getting sub field. Default value: `false` (current post). $args _(array) (Optional)_
Array of image output arguments. Default value: `null`.     **«size»** _(string)_
Image size to use. Accepts any valid image size. Default value is `full`.     **«
alt»** _(string)_ `alt` attribute of the image.     **«id»** _(string)_ `id` attribute
of the image.     **«class»** _(string)_ `class` attribute of the image.     **«
title»** _(string)_ `title` attribute of the image.     **«srcset»** _(bool)_ Use`
true` for retrieving image’s `srcset` attribute. Default value: `false`.     **«
loading»** _(string)_ `loading` attribute of the image. Default value: `lazy`.  **«
link»** _(bool|array)_ Array of attributes for anchor wrapped around the image. 
Default value: `false`.         **«href»** _(string)_ `href` attribute of the link.**«
target»** _(string)_ `target` attribute of the link.         **«class»** _(string)_`
class` attribute of the link.         **«id»** _(string)_ `id` attribute of the 
link.         **«title»** _(string)_ `title` attribute of the link.

#### Repeater

Displays the snippet of a specific repeater field.

    ```
    <?php
        acf_snippet_the_repeater($selector, [$postId], [$args]);
    ?>
    ```

**Parameters**
 $selector _(string) (Required)_ ACF field name or ACF field key.
Based on [ACF get_field function](https://www.advancedcustomfields.com/resources/get_field/).
$postId _(integer|bool) (Optional)_ The post ID where the value is saved. Default
value: `false` (current post). $args _(array) (Optional)_ Array of repeater output
arguments. Default value: `null`.     **«template»** _(string|array)_ Template for
items inside the loop. Arguments of `get_template_part` function. In the template
use standard `get_sub_field function`.     **«wrap_before»** _(string)_ Text (HTML)
before repeater items while have rows.     **«wrap_after»** _(string)_ Text (HTML)
after repeater items while have rows     **«empty_html»** _(string)_ Text (HTML)
in case there are no rows in repeater.

#### Flexible content

Displays the snippet of a specific flexible field.

    ```
    <?php
        acf_snippet_the_flexible_content($selector, [$postId], [$args]);
    ?>
    ```

**Parameters**
 $selector _(string) (Required)_ ACF field name or ACF field key.
Based on [ACF get_field function](https://www.advancedcustomfields.com/resources/get_field/).
$postId _(integer|bool) (Optional)_ The post ID where the value is saved. Default
value: `false` (current post). $args _(array) (Optional)_ Array of flexible content
output arguments. Default value: `null`.     **«templates»** _(array)_ Array of 
templates for flexible content layouts. In the templates use standard `get_sub_field
function`.         key _(string)_ – layout name         value _(string|array)_ arguments
for `get_template_part` function.

_Requires Advanced Custom Fields (Pro)_

#### Examples

**Link field**

    ```
    <?php
        acf_snippet_the_link('more_info_link', false, [
            'class'=> 'link__out',
            ]
        );
    ?>
    ```

**Image field**

    ```
    <?php
        echo acf_snippet_get_image('logo', 'option', [
            'size' => 'medium',
            'alt' => 'company name',
            'title' => false,
            'class' => 'header__logo',
            'id' => 'company-logo',
            'loading' => 'fetch',
            'link' => [
                'href' => get_home_url()
                ]
            ]
        );
    ?>
    ```

**Repeater field**

    ```
    <?php
        acf_snippet_the_repeater( 'team_members', false, [
            'template'    => [ 'templates/loops/loop', 'team-member' ],
            'wrap_before' => '<ul class="about__team">',
            'wrap_after'  => '</ul>',
            'empty_html'  => '<p>' . __( 'No team members to show.', 'web' ) . '</p>'
            ]
        );
    ?>
    ```

**Flexible content field**

    ```
    <?php
        acf_snippet_the_flexible_content( 'fp_content', false, [
        'templates' => [
            'slider'          => [ 'templates/homepage/snippet', 'slider' ],
            'counters' => [ 'templates/homepage/snippet', 'counters' ],
            'text_block'    => [ 'templates/homepage/snippet', 'text_block' ]
            ]
        ] 
    );
    ```

?>
 `

## Omtalar

There are no reviews for this plugin.

## Bidragsytarar og utviklarar

“Advanced Custom Fields: Snippets” is open source software. The following people
have contributed to this plugin.

Contributors

 *   [ tomekthewo ](https://profiles.wordpress.org/tomekthewo/)

[Omset “Advanced Custom Fields: Snippets” til ditt eige språk.](https://translate.wordpress.org/projects/wp-plugins/acf-snippets)

### Interested in development?

[Les kjeldekoden](https://plugins.trac.wordpress.org/browser/acf-snippets/), sjekk
[SVN-lageret](https://plugins.svn.wordpress.org/acf-snippets/) eller abonner på 
[utviklingsloggen](https://plugins.trac.wordpress.org/log/acf-snippets/) med [RSS](https://plugins.trac.wordpress.org/log/acf-snippets/?limit=100&mode=stop_on_copy&format=rss).

## Endringslogg

#### 1.0

 * init

## Om

 *  Version **1.0.0**
 *  Last updated **7 år sidan**
 *  Active installations **Færre enn 10**
 *  WordPress version ** 4.8 eller nyare **
 *  Tested up to **5.2.24**
 *  PHP version ** 5.4 eller nyare **
 *  Language
 * [English (US)](https://wordpress.org/plugins/acf-snippets/)
 * Tags
 * [acf](https://nn.wordpress.org/plugins/tags/acf/)[advanced custom fields](https://nn.wordpress.org/plugins/tags/advanced-custom-fields/)
 *  [Avansert vising](https://nn.wordpress.org/plugins/acf-snippets/advanced/)

## Vurderingar

No reviews have been submitted yet.

[Your review](https://wordpress.org/support/plugin/acf-snippets/reviews/#new-post)

[See all reviews](https://wordpress.org/support/plugin/acf-snippets/reviews/)

## Contributors

 *   [ tomekthewo ](https://profiles.wordpress.org/tomekthewo/)

## Hjelp

Har du noko å seia? Treng du hjelp?

 [Sjå hjelpeforumet](https://wordpress.org/support/plugin/acf-snippets/)

## Donate

Would you like to support the advancement of this plugin?

 [ Donate to this plugin ](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=M2L5UJG9JEWXU&source=url)