> For the complete documentation index, see [llms.txt](https://wplake.gitbook.io/advanced-views/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wplake.gitbook.io/advanced-views/layouts/embedding-shortcode.md).

# Layout embedding shortcode

In Advanced Views, [*Layout*](/advanced-views/getting-started/first-layout.md) embedding happens using native WordPress shortcodes. Each *Layout* has its own unique shortcode that can be pasted into any location, regardless of the theme, editor, or page builder you're using.&#x20;

Shortcodes also support arguments, allowing you to customize the behavior of the same entity in different contexts.

## 1. Shortcode format

Each *Layout* shortcode should contain at least 2 arguments:

```bbcode
[avf-layout name="Name" id="651d5d75bfdf2"]
```

1. `name` argument - used for clarification purposes only and doesn't play any functional role.&#x20;
2. `id` argument - associates the shortcode with a specific *Layout*.

By default, the shortcode uses the current object (Post, Page, Product, or any Custom Post Type) where it is placed as the fields source. To use a different object as the fields source, define the `object-id` argument described below:

## 2. "object-id" argument

Using `object-id` shortcode argument, you can change the *Layout* fields source and display fields from any WordPress object. Below is the overview:

| Fields source                                                                                                                                 | "object-id" argument                                                  |
| --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
| [current Post](/advanced-views/field-sources/post.md)                                                                                         | (omitted)                                                             |
| [specific Post](/advanced-views/field-sources/post.md), resolved by the ID                                                                    | `object-id="NUMERIC_ID"`                                              |
| [specific Post](/advanced-views/field-sources/post.md), resolved by the slug                                                                  | <p><code>object-id="post"</code><br><code>post-slug="SLUG"</code></p> |
| [Options page](/advanced-views/field-sources/options-page.md)                                                                                 | `object-id="options"`                                                 |
| [current User](/advanced-views/field-sources/user-profile.md) (logged-in user viewing the page, not the static user who created the *Layout*) | `object-id="user"`                                                    |
| [specific User](/advanced-views/field-sources/user-profile.md)                                                                                | `object-id="user" user-id="NUMERIC_ID"`                               |
| [current Taxonomy term](/advanced-views/field-sources/objects/taxonomy-term.md) (only if you paste the shortcode on the term template/page)   | `object-id="term"`                                                    |
| [specific Taxonomy term](/advanced-views/field-sources/objects/taxonomy-term.md)                                                              | `object-id="term" term-id="NUMERIC_ID"`                               |
| [specific Comment](/advanced-views/field-sources/objects/comment.md)                                                                          | `object-id="comment" comment-id="NUMERIC_ID"`                         |
| [specific Menu](/advanced-views/field-sources/objects/menu.md)                                                                                | `object-id="menu" menu-slug="SLUG"`                                   |
| [specific Menu item](/advanced-views/field-sources/objects/menu-item.md)                                                                      | `object-id="NUMERIC_ID"` (the same as Post)                           |

{% hint style="info" %}
This table refers to "Post" as a generic WordPress term that covers Post, Page, any Custom Post Type, Media attachment, Woo Product, and other entities. With Advanced Views, you can display fields from any entity.
{% endhint %}

## 3. Common arguments

The following shortcode arguments can be added to any *Layout* shortcode:

### 3.1) class - adding HTML class

This argument allows you to add a class to your *Layout* main wrapper dynamically.&#x20;

In most cases, you should add all the classes directly to your *Layout,* but in some cases you will need to assign this class dynamically. For example, inside your *Post Selection*, you may want to add a specific class to your *Layout* that is specific to this *Post Selection* only.&#x20;

{% code overflow="wrap" %}

```shortcode
[avf-layout name="Name of Layout" id="651d5d75bfdf2" class="YOUR_CLASS_HERE"]
```

{% endcode %}

### 3.2) user-with-role - restricting visibility by role

Both "user-with-roles" and "user-without-roles" arguments allow you to restrict access to the specific *Layout*.&#x20;

{% code overflow="wrap" %}

```shortcode
[avf-layout name="Name of Layout" id="651d5d75bfdf2" 
user-with-roles="ROLE1,ROLE2" user-without-roles="ROLE1,ROLE2"]
```

{% endcode %}

{% hint style="info" %}
"**Restrict**" means that the shortcode won't be rendered, so if you'd like to show a restriction type message to users, then consider customizing the *Layout* template to check user roles ther&#x65;*.*
{% endhint %}

### 3.3) custom-arguments - transiting fields

Using this argument, you can pass any custom arguments to the [*Layout* Controller](/advanced-views/layouts/code-fields/layout-controller.md):

{% code overflow="wrap" %}

```shortcode
[avf-layout name="Name of Layout" id="651d5d75bfdf2" custom-arguments="name=value,another-name=another-value"]
```

{% endcode %}

{% hint style="warning" %}
Custom arguments are available only inside the *Layout* Controller. They're not available directly in the *Layout* template. If you need to use them inside the template, you can transit them in the snippet.  &#x20;
{% endhint %}

## 4. Displaying inside theme templates

To embed *Layout* into theme templates, you can either render the text shortcode using a native [WordPress do\_shortcode function](https://developer.wordpress.org/reference/functions/do_shortcode/), or employ the Advanced Views API:&#x20;

{% code overflow="wrap" %}

```php
<?php

// a) using WordPress do_shortcode
echo do_shortcode('[avf-layout name="Name of Layout" id="651d5d75bfdf2"]');

// b) using the special plugin class
use Org\Wplake\Advanced_Views\Bridge\Advanced_Views;

echo Advanced_Views::layout_shortcode('651d5d75bfdf2', 'name')
// ->set_object_id(10)
// adds HTML class to the main wrapper
 // ->set_class('YOUR_CLASS_HERE')
 // restricts access by roles
 // ->set_user_with_roles(['administrator'])
 // ->set_user_without_roles(['suspended'])
 // you can pass custom arguments, including objects, arrays, etc.  
//->set_custom_arguments([
    //    'name' => 'value',
       // 'another-name' => ['my array'],
   // ])
    ->render();
```

{% endcode %}
