When you use a check for $element_id in the filter, as in the above doc page examples, like this:
if ( $element_id === 'yjqekk' ) { //do something }
The $element_id checked against here is the ‘internal’ element id consisting of random characters.
It is not checking the elements’ ID as set in its setting in the left top: Screen Shot 2023-02-14 at 15.03.17.png - Droplr
Maybe I’m missing something here, but I’d expect you can set an element to a custom ID, and then check against it in this filter.
I tried this with a ‘Block’ element and a ‘Post’ element. For both only the randomized original ID works in the filter. The templates/blocks are properly saved of course after adding the custom ID. And the custom ID is present on the front-end as id attribute.
No, the ID that is output on the front end is different to the element_id here. They’re separate things, they only look similar to start with because Bricks uses that element ID when it first has to create an ID for the element to add styles to, but when/if that’s changed, it doesn’t effect the actual real element ID.
delete your custom ID, and then Bricks will return the original ID that will look like #brxe-XXXXX where XXXXX is the ID you’re needing in your code for that element.
I just ran into the same problem and through google came across this thread. I think this Bricks action (using automatic and hidden ID) is incorrect. I have several pages that have almost identical structure and for which I would like to have ONE filter. So I set a static ID in each of these pages (the same for a specific element), but I found that this does not work. And now I have to add in the filter code all the IDs generated by Bricks in each of these pages (and in the future remember that!), so that each of the pages can be processed by the filter, even though their code is structurally almost identical! This is a big hassle.
@Matej thanks, never noticed that icon before.
But the issue is that it’s unclear that this id is something else than what is shown in the input box, which is apparently called the ‘CSS ID’ (I see from the copy icon of that), which is not clear from the UI.
Adding to the confusion, in the filter and on the filter’s doc page, it is called ‘element_id’. So there is bricks ID, CSS ID and element ID, of which the first and last are the same.
It would be helpful to mention this on the page of the bricks/posts/query_vars filter.