I was wondering of it's possible to use custom fields to fill either a class or a background color. For instance, I created a custom field, a select list, with a choice of 4 colors.
In the same spirit, would it be ok to do something like this?
<div class="[wpv-post-taxonomy type="category" format="name"]">
whatever inside
</div>
As I'm trying to apply a different color according to which category the custom post type I created is associated with.
The site is still under construction, so no worries there.
Maybe I'm trying to achieve that but going totally the wrong way: I'd be grateful if you could point me towards the right direction.
Thanks!
Yes, I did try: the background <div> is displayed white (or blank) if I use that piece of code:
<div style="background:[types field='couleur' output='raw'][/types]">
I also tried that : <div class="[wpv-post-taxonomy type="category" format="name"]"> but only he <div> is displayed, without the class element.
I did try to insert this into a view:
[types field='couleur' output='raw'][/types] => this works fine
However, this (in Toolset Views): <p style="color:[types field='couleur' output='raw'][/types]">test</p> is displayed as <p>test</p> on the front end.
Same thing goes for the background or class I would add, they're just stripped off.
To be more precise, I have built a view which I put inside a text module (Divi theme) using a shortcode. I don't understand why the class and styles are stripped though, unless it is running as it should.
Could you tell me where you used your code: inside a view and then using a shortcode to display it or elsewhere?
I was using a content template, so I just tried this with a View, inserted into a Divi text module, and it still worked (you can see the generated markup in the screenshot).
I tried various different things in an attempt to make it not work, but couldn't, it always worked.
I'm guessing something else is in play on your site.
Can you try this with as minimal an installation as possible? Disable all plugins except Types and Views. Also try it without Divi (on a page using the classic editor, and after switching theme if necessary).
Yes, I figured I would have to test that on a blank WordPress installation. I'll keep you posted if I manage to find the culprit, let you know what might be causing this.
I spent most of the day to try and solve this. On a blank empty installation, I noticed that I had to comment this line in wp-config.php to make it work properly:
define( 'DISALLOW_UNFILTERED_HTML', true );
Otherwise, it strips the class and style from the div and p tags. I just found out, thought I'll let you know.