> For the complete documentation index, see [llms.txt](https://docs.yaycommerce.com/yayswatches/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.yaycommerce.com/yayswatches/how-it-works/hooks-and-shortcodes.md).

# Hooks and Shortcodes

1. **Hooks**

* Filter **yay\_swatches\_show\_all\_pages** hook is used to display YaySwatches on a page.

Currently in YaySwatches settings, attributes are displayed only on Single Product Page and Shop/Categories Page. To display YaySwatches on other pages, you can add the following code to [Code Snippets](https://wordpress.org/plugins/code-snippets/) or to the file `functions.php` of your theme.&#x20;

```
add_filter( 'yay_swatches_show_all_pages', '__return_true' );
```

* Filter hook to show/hide term name on variant: **yay\_swatches\_show\_term\_name\_variant\_button, yay\_swatches\_show\_term\_name\_variant\_custom, yay\_swatches\_show\_term\_name\_variant\_image**

```
add_filter( 'yay_swatches_show_term_name_variant_button', '__return_true' );
add_filter( 'yay_swatches_show_term_name_variant_custom', '__return_true' );
add_filter( 'yay_swatches_show_term_name_variant_image', '__return_true' );
```

2. **Shortcodes**

* `[yay-swatches-variant-html]`: You can use this shortcode to display YaySwatches by product ID

Eg: Display attribute of product ID 21

<figure><img src="/files/RDgV8vhP6EkRuzdXOQbK" alt=""><figcaption><p>Add YaySwatches shortcode to display attribute</p></figcaption></figure>

<figure><img src="/files/JULYvgmlPiEPi5G8FbLZ" alt=""><figcaption><p>Attribute displayed in the front end</p></figcaption></figure>

* `[yay-swatches-variant-loop]` shortcode is to show YaySwatches in Products Loop.

<figure><img src="/files/pWNbSzhTAUKUBfyucKhC" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/X65uqQB9nPTXWDnb5XHn" alt=""><figcaption></figcaption></figure>

3. **Custom CSS**

* Make some space between the variant name and the image swatch or button

```
.single-product div.product table.variations .value {
padding-bottom: unset !important;
}

.yay-swatches-wrapper .variations_form.cart .variations .value {
padding-top: 12px;
}

.yay-swatches-swatch {
margin: 0px 16px 10px 0px !important;
}

.yay-swatches-button {
margin-right: 16px !important;
}
```

* Remove "Clear option" from the front end

```
.yay-swatches-wrapper .variations_form.cart .variations .reset_variations {
display: none !important;
},
```

{% hint style="info" %}
These provided hooks and shortcodes are fully functional only in the YaySwatches pro version.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.yaycommerce.com/yayswatches/how-it-works/hooks-and-shortcodes.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
