# Best method to make parts of CSS class names dynamic with php?

**URL:** <https://forum.pinegrow.com/t/best-method-to-make-parts-of-css-class-names-dynamic-with-php/8006>\
**Category:** WordPress\
**Created:** [May 5, 2023, 11:25am UTC](https://forum.pinegrow.com/t/best-method-to-make-parts-of-css-class-names-dynamic-with-php/8006 "2023-05-05T11:25:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichelyWeb](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/michelyweb/32/6652_2.png) [@MichelyWeb](https://forum.pinegrow.com/u/MichelyWeb)\
**Post date:** [May 5, 2023, 11:25am UTC](https://forum.pinegrow.com/t/best-method-to-make-parts-of-css-class-names-dynamic-with-php/8006/1 "2023-05-05T11:25:47Z")

</div>

![CleanShot 2023-05-05 at 13.18.36@2x](https://canada1.discourse-cdn.com/flex036/uploads/pinegrow/original/2X/8/8160299d4a76ca00654eecbfbcb3b1f0e30a4d2f.png)

Because inside of double quotes is not possible i do it this way:

```auto
<button id=<php> echo "trtmntacc-header-" . get_row_index(); </php> aria-expanded="false" aria-controls=<php> echo "trtmntacc-panel-" . get_row_index(); </php> data-accordion-header class="accordion__header">My Button</button>

```

Is there a better way?

---

<div class="post-metadata">

**Author:** ![MichelyWeb](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/michelyweb/32/6652_2.png) [@MichelyWeb](https://forum.pinegrow.com/u/MichelyWeb)\
**Post date:** [May 5, 2023, 11:34am UTC](https://forum.pinegrow.com/t/best-method-to-make-parts-of-css-class-names-dynamic-with-php/8006/2 "2023-05-05T11:34:58Z")

</div>

Oh no. The second approach doesn’t work either.

 ![CleanShot 2023-05-05 at 13.33.46@2x](https://canada1.discourse-cdn.com/flex036/uploads/pinegrow/original/2X/f/ff45a65a1d532597d4adab9231441d0077468dfc.png)

---

<div class="post-metadata">

**Author:** ![MichelyWeb](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/michelyweb/32/6652_2.png) [@MichelyWeb](https://forum.pinegrow.com/u/MichelyWeb)\
**Post date:** [May 5, 2023, 12:22pm UTC](https://forum.pinegrow.com/t/best-method-to-make-parts-of-css-class-names-dynamic-with-php/8006/3 "2023-05-05T12:22:47Z")

</div>

For now i am using a PHP Smart Action echoing the complete `<button ....>` and then again a PHP Smart Action for the `</button>`.

 ![CleanShot 2023-05-05 at 14.24.09@2x](https://canada1.discourse-cdn.com/flex036/uploads/pinegrow/original/2X/2/27a8f08100ff720710779dd5ec3ab22737b6d42e.png)

It works but is uncomfortable and makes it impossible to change the button attributes inside of the PG Panels.

I am sure, there is a better solution. Right @Emmanuel @matjaz ?

---

<div class="post-metadata">

**Author:** ![MichelyWeb](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/michelyweb/32/6652_2.png) [@MichelyWeb](https://forum.pinegrow.com/u/MichelyWeb)\
**Post date:** [May 9, 2023, 1:38pm UTC](https://forum.pinegrow.com/t/best-method-to-make-parts-of-css-class-names-dynamic-with-php/8006/4 "2023-05-09T13:38:29Z")

</div>

Okay… after staying away some time and come back to this problem here’s how it works:

```auto
<button id="<?php echo 'trtmntacc-header-' . get_row_index(); ?>">My Button Text</button>

```

Was just a matter of single and double quotes… phew… 🫣

---

<div class="post-metadata">

**Author:** ![matjaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/matjaz/32/5_2.png) [@matjaz](https://forum.pinegrow.com/u/matjaz)\
**Post date:** [May 10, 2023, 5:31am UTC](https://forum.pinegrow.com/t/best-method-to-make-parts-of-css-class-names-dynamic-with-php/8006/5 "2023-05-10T05:31:40Z")

</div>

@MichelyWeb congrats for figuring it out! 🙂

Another way would be:

```auto
<button id="trtmntacc-header-<?php echo get_row_index(); ?>">Hello</button>

```

This avoids having to use nested quotes.

---

<div class="post-metadata">

**Author:** ![MichelyWeb](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/michelyweb/32/6652_2.png) [@MichelyWeb](https://forum.pinegrow.com/u/MichelyWeb)\
**Post date:** [May 10, 2023, 6:19am UTC](https://forum.pinegrow.com/t/best-method-to-make-parts-of-css-class-names-dynamic-with-php/8006/6 "2023-05-10T06:19:34Z")

</div>

Right. It’s better doing it that way.

I’m sure i tried all of this in the beginning and couldn’t get it to work. Therefore this complicated detour to the obvious solution. 🙂
