Hi,
Could you please advice me proper way to add markup attribute defined in admin panel through post custom values ( or fields)?
My case is that I'd like to add inline styling to beans-post-header
- background color in this case. As far I've learned I could wrap the header and style the wrapping, or overwrite loop.php
, i guess, but I don't want to add unnecessary html, and new loop.php
file in child theme doesn't make a lot of sense when it goes about such small modification, so I'd rather have something like:
beans_add_attribute('beans-post-header', 'style', get_post_custom_values('custom_color')[0]);
or
beans_add_attribute('beans-post-header', 'style', beans_get_post_meta( 'custom_color' ));
I feel I misunderstand whole concept, so I'd be greatfull for clearing that up, or pointing me out some resources to learn.
Hi Anna,
You understood the concept perfectly well 🙂 The issue here is the markup id, your are using -
instead of _
. The markup id for the post header is beans_post_header
(refer to this reply for more info about the hooks and markup id). For example the code below would make the post header background red:
beans_add_attribute( 'beans_post_header', 'style', 'background: red;' );
Regarding pulling from the admin, yes you can totally do that! You have to register a field for it and retrieve the data which you can then use to add your attribute.
Have fun,
Thanks for response!
I'm very sorry, there was a typo only in my post - code returnsstyle=url()
in proper markup. I just don't know how to retrieve the custom data in functions.php
.
Hey Anna,
Could you paste the code you are using the register the field so that I can provide you with a complete working snippet. Here is a discussion which might help you too.
Thanks,
Thank you, link was very helpful. I was trying to reach those attributes without any action, barely in functions.php
.
Great stuff Anna, I am happy to hear you managed to get it working.
Keep up the good work and have fun,