Master the fundamentals of Custom CSS to create unlimited styling possibilities beyond the plugin’s dropdown options
The Custom CSS feature in WhoKnew Views™ allows you to write your own CSS code to override or extend any styling setting in the plugin. While the Styling tab provides dozens of dropdown options, sliders, and color pickers, Custom CSS gives you unlimited creative freedom to:
- 🎨 Override any plugin setting – Change colors, fonts, sizes, positions, animations
- 🎯 Target specific products – Style counters differently for different products or categories
- ✨ Create advanced effects – Build animations, gradients, and hover effects beyond dropdown options
- 📱 Custom responsive behavior – Write media queries for unique breakpoints or devices
- 🔧 Fix edge cases – Resolve theme conflicts, alignment issues, or browser-specific quirks
🎯 Overview: What is Custom CSS?
This article is your complete guide to getting started with Custom CSS. You’ll learn where to find the Custom CSS box, understand CSS selector hierarchy, master per-product targeting, and avoid common mistakes.
⚠️ Important: Custom CSS Requires Basic CSS Knowledge
This guide assumes you understand CSS fundamentals (selectors, properties, values). If you’re new to CSS, we recommend starting with the Styling tab’s dropdown options, which require zero coding. Custom CSS is for advanced users who need granular control.
📍 Where to Find the Custom CSS Box
The Custom CSS input is located at the very bottom of the Styling tab, in its own dedicated section:
- Go to WhoKnew → WhoKnew Views → Styling tab
- Scroll past all the dropdown sections (Icon Styling, Text Styling, Layout, etc.)
- At the bottom, you’ll see 💻 Custom CSS section
- Click to expand it (if collapsed)
- Inside is a large textarea where you write your CSS
Visual landmark: Just above the Custom CSS box, you’ll see the “Explore Our Premium CSS Gallery” card with a gradient purple background. This card links to 100+ ready-to-use CSS examples. The Custom CSS textarea is directly below this card.
What the Custom CSS Box Looks Like
| Element | Description |
|---|---|
| Title | “Custom CSS” (with 💻 icon) |
| Input Type | Large textarea (monospace font for code readability) |
| Description | “Add custom CSS to create unique styling for your view counter. Explore the CSS Gallery above for production-ready examples you can copy and customize.” |
| Placeholder | Empty (ready for your CSS) |
Pro tip: The Custom CSS box updates the live preview automatically as you scroll the page or click outside the textarea. You don’t need to save settings to see changes in the preview iframe!
🧩 Understanding CSS Selector Hierarchy
To style view counters with Custom CSS, you need to target the correct HTML elements. WhoKnew Views™ uses a structured DOM hierarchy with specific CSS classes:
The Counter HTML Structure
<div class="product-views-counter">
<div class="view-counter-wrapper">
<div class="view-counter-icon-wrapper">
<i class="view-counter-icon ion-ios-eye"></i>
</div>
<span class="view-counter-text">42 views in 48 hours</span>
</div>
</div>The Four Key Selectors
| Selector | Targets | Use For |
|---|---|---|
.product-views-counter | The entire counter container (outermost div) | Position, width, z-index, opacity, rotation, padding, margin |
.view-counter-wrapper | The inner wrapper (holds icon + text) | Background, border, box-shadow, flex direction, gap, border-radius |
.view-counter-icon-wrapper | The icon container (wraps the icon element) | Icon wrapper size, alignment, filter (for icon shadows) |
.view-counter-icon | The actual icon (e.g., eye icon from Ionicons) | Icon color, size, animations, transforms |
.view-counter-text | The text (e.g., “42 views in 48 hours”) | Font family, size, color, letter spacing, text shadows |
Example: Basic Selector Usage
/* Change the entire counter's background to blue */
.view-counter-wrapper {
background: #3b82f6 !important;
}
/* Make the icon bright red */
.view-counter-icon {
color: #ef4444 !important;
}
/* Enlarge the text to 18px */
.view-counter-text {
font-size: 18px !important;
}Key point: Always include .product-views-counter or its child selectors in your Custom CSS. If you just write .my-custom-class, it won’t target the counter because that class doesn’t exist in the counter’s HTML.
🚨 The !important Flag: When to Use It
You’ll notice !important in most Custom CSS examples. This CSS flag forces your rule to override the plugin’s built-in styles. Here’s when to use it:
✅ When to Use !important
- Overriding plugin dropdowns – If a dropdown sets
color: #000000, your Custom CSS needs!importantto win - Overriding theme CSS – If your theme has very specific selectors or inline styles
- Mobile overrides – When your mobile styles need to beat desktop styles
- Hover effects – When hover states aren’t applying due to specificity issues
❌ When to Avoid !important
- Inside @keyframes – Animation keyframes cannot use
!important(invalid CSS) - If it already works – If your CSS applies without
!important, don’t add it (cleaner code) - Complex selectors – If you use a very specific selector, you may not need
!important
How !important Works
/* Plugin's built-in CSS */
.view-counter-text {
color: #000000; /* Black (from dropdown) */
}
/* Your Custom CSS WITHOUT !important (LOSES) */
.view-counter-text {
color: #ef4444; /* Red */
}
/* Result: Text stays black (plugin wins) */
/* Your Custom CSS WITH !important (WINS) */
.view-counter-text {
color: #ef4444 !important; /* Red */
}
/* Result: Text becomes red (you win) */Rule of thumb: Start with !important on every rule in Custom CSS. Remove it only if you’re confident your selector specificity is high enough to override the plugin naturally.
🎯 Per-Product Targeting: The .postid-X Selector
One of Custom CSS’s most powerful features is per-product targeting. WordPress automatically adds a .postid-123 class to the <body> tag on every product page, where 123 is the product’s ID.
How to Find a Product’s ID
Method 1: Product Edit URL
- Go to Products → All Products
- Hover over a product and click Edit
- Look at the URL:
post.php?post=456&action=edit - The number after
post=is the product ID (e.g., 456)
Method 2: Browser DevTools (While Viewing Product)
- Visit the product page on your live site
- Right-click anywhere → Inspect
- In the Elements tab, scroll to the top to find the
<body>tag - Look for
<body class="... postid-456 ..."> - The number after
postid-is the product ID (e.g., 456)
Using .postid-X in Custom CSS
/* Target ONLY product ID 456 */
.postid-456 .view-counter-wrapper {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
padding: 15px 30px !important;
border-radius: 20px !important;
}
/* Target ONLY product ID 789 */
.postid-789 .view-counter-text {
color: #ef4444 !important;
font-size: 20px !important;
font-weight: 700 !important;
}
/* Target ONLY product ID 123 - hide counter entirely */
.postid-123 .product-views-counter {
display: none !important;
}Targeting Multiple Products
Use comma-separated selectors to apply the same CSS to multiple products:
/* Target products 101, 102, and 103 */
.postid-101 .view-counter-wrapper,
.postid-102 .view-counter-wrapper,
.postid-103 .view-counter-wrapper {
background: #10b981 !important;
color: #ffffff !important;
}💡 Pro Tip: Use Per-Product for Premium Products
Create a “premium product” style with bold colors and larger text, then apply it to your high-ticket items using .postid-X selectors. This draws extra attention to products that drive the most revenue.
🏷️ Category-Based Targeting
WordPress also adds category classes to the <body> tag. If a product is in the “Electronics” category, the body will have a class like .product_cat-electronics.
How to Find Category Slugs
- Go to Products → Categories
- Hover over a category and click Edit
- Look for the Slug field (e.g.,
electronics,clothing) - The body class will be
.product_cat-electronics
Category Targeting Examples
/* Target ALL products in "Electronics" category */
.product_cat-electronics .view-counter-wrapper {
background: #3b82f6 !important;
border: 2px solid #1e40af !important;
}
/* Target ALL products in "Clothing" category */
.product_cat-clothing .view-counter-icon {
color: #ec4899 !important;
}
/* Target products in BOTH "Sale" AND "Featured" categories */
.product_cat-sale.product_cat-featured .view-counter-text {
color: #ef4444 !important;
font-weight: 700 !important;
text-transform: uppercase !important;
}Use case: Style counters differently for each product category to match your brand’s color scheme. Electronics = blue, Clothing = pink, Home & Garden = green, etc.
🧪 Testing CSS in Browser DevTools
Before adding CSS to the Custom CSS box, test it live in your browser to ensure it works. This saves time and prevents mistakes.
Step-by-Step Testing Workflow
- Visit a product page on your live site (not the admin preview)
- Right-click on the view counter → Inspect
- In DevTools, find the
.product-views-counterelement - In the Styles panel (right side), click the + icon to add a new rule
- Type your selector (e.g.,
.view-counter-text) and press Enter - Add CSS properties inside the rule (e.g.,
color: red;) - Watch the counter change in real-time as you type
- Once satisfied, copy the CSS from DevTools into the Custom CSS box
Example: Testing a Text Color Change
| Step | Action in DevTools | Result |
|---|---|---|
| 1 | Inspect .view-counter-text | See current styles (e.g., color: #000000;) |
| 2 | Click + to add new rule | Empty rule appears |
| 3 | Type .view-counter-text | Selector is set |
| 4 | Type color: #ef4444 !important; | Text turns red instantly |
| 5 | Copy CSS from DevTools | Ready to paste into Custom CSS box |
Pro tip: DevTools changes are temporary—they disappear on page refresh. Always copy working CSS into the Custom CSS box and save settings to make changes permanent.
🛠️ How Custom CSS is Applied
Understanding when and how your Custom CSS is injected helps you troubleshoot issues:
The CSS Cascade (Execution Order)
- Plugin’s built-in CSS (from dropdown settings) loads first
- Your Custom CSS loads second (after dropdown settings)
- Theme CSS may load before or after, depending on your theme
- Inline styles (rare, but highest priority if present)
Why this matters: Your Custom CSS always loads after the plugin’s built-in styles, so it can override dropdown settings. But if your theme has very specific selectors or uses !important, you may need to increase your selector specificity.
Where Custom CSS is Injected
WhoKnew Views™ injects Custom CSS into the <head> of your site using wp_enqueue_scripts. You can verify this by viewing your page source (Ctrl+U / Cmd+U) and searching for wkv_custom_css.
<style id="wkv-custom-css">
/* Your Custom CSS appears here */
.view-counter-text {
color: #ef4444 !important;
}
</style>Sanitization: For security, WhoKnew Views™ sanitizes your Custom CSS before injecting it. This removes dangerous code (like <script> tags) but preserves all valid CSS. If your CSS isn’t applying, check for syntax errors (missing semicolons, unclosed braces, etc.).
🚫 Common Mistakes to Avoid
Mistake 1: Forgetting !important
Problem: CSS doesn’t apply because plugin dropdowns use !important.
/* ❌ WRONG: No !important, plugin wins */
.view-counter-text {
color: red;
}
/* ✅ CORRECT: With !important, you win */
.view-counter-text {
color: red !important;
}Mistake 2: Wrong Selector
Problem: Targeting a class that doesn’t exist in the counter’s HTML.
/* ❌ WRONG: .counter-text doesn't exist */
.counter-text {
color: red !important;
}
/* ✅ CORRECT: Use exact class from HTML */
.view-counter-text {
color: red !important;
}Mistake 3: Missing Semicolons or Braces
Problem: CSS syntax errors break the entire rule block.
/* ❌ WRONG: Missing semicolon after color */
.view-counter-text {
color: red
font-size: 18px !important;
}
/* ✅ CORRECT: Semicolon after every property */
.view-counter-text {
color: red;
font-size: 18px !important;
}Mistake 4: Overriding Position with Width/Height
Problem: Setting width: 100% on .product-views-counter when it’s already positioned absolutely.
/* ❌ WRONG: Full width on absolutely positioned element */
.product-views-counter {
position: absolute;
width: 100% !important; /* Counter stretches across entire image */
}
/* ✅ CORRECT: Set width on wrapper, not outer container */
.view-counter-wrapper {
width: 300px !important;
}Mistake 5: Using !important in @keyframes
Problem: !important is invalid inside animation keyframes.
/* ❌ WRONG: !important in keyframes (invalid) */
@keyframes fadeIn {
from { opacity: 0 !important; }
to { opacity: 1 !important; }
}
/* ✅ CORRECT: No !important in keyframes */
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.view-counter-wrapper {
animation: fadeIn 1s ease !important; /* !important here is fine */
}Mistake 6: Not Testing After Saving
Problem: Assuming preview behavior matches live site behavior.
Solution: Always test on a live product page after saving Custom CSS. The preview iframe may render differently than your actual theme.
💡 Tips for Writing Maintainable Custom CSS
1. Add Comments
Use /* comments */ to document what each rule does:
/* Make premium products (ID 101-105) stand out */
.postid-101 .view-counter-wrapper,
.postid-102 .view-counter-wrapper,
.postid-103 .view-counter-wrapper {
background: linear-gradient(135deg, #f59e0b 0%, #ef938a93c2@0ade0335.com%) !important;
border: 2px solid #fbbf24 !important;
}
/* Hide counter on "Coming Soon" product (ID 999) */
.postid-999 .product-views-counter {
display: none !important;
}2. Group Related Rules
Keep per-product rules together, category rules together, etc.:
/* ===== CATEGORY STYLES ===== */
.product_cat-electronics .view-counter-wrapper {
background: #3b82f6 !important;
}
.product_cat-clothing .view-counter-wrapper {
background: #ec4899 !important;
}
/* ===== PER-PRODUCT OVERRIDES ===== */
.postid-123 .view-counter-text {
font-size: 20px !important;
}
.postid-456 .product-views-counter {
display: none !important;
}3. Use Consistent Formatting
Indent properties, one property per line, alphabetical order (optional but helpful):
/* ✅ GOOD: Readable, consistent formatting */
.view-counter-wrapper {
background: #3b82f6 !important;
border-radius: 20px !important;
padding: 15px 30px !important;
}
/* ❌ BAD: Cramped, hard to read */
.view-counter-wrapper{background:#3b82f6!important;border-radius:20px!important;padding:15px 30px!important;}4. Start Simple, Add Complexity Gradually
Test one rule at a time. Don’t paste 100 lines of CSS and hope it works. Add rules incrementally and verify each one applies correctly.
🔍 Troubleshooting: “My CSS Isn’t Working”
Checklist for Debugging
- ✅ Check for syntax errors – Missing semicolons, unclosed braces, typos in property names
- ✅ Add !important – If missing, the plugin’s dropdowns may be overriding you
- ✅ Verify selector is correct – Use DevTools to confirm the class exists in the HTML
- ✅ Clear cache – Browser cache or caching plugins may serve old CSS
- ✅ Test on live site – Preview iframe may render differently than real pages
- ✅ Check browser console – Open DevTools → Console tab, look for CSS parsing errors
- ✅ Inspect computed styles – In DevTools, check the “Computed” tab to see which rule won
Using DevTools to Debug
- Inspect the counter element (right-click → Inspect)
- In the Styles panel, look for your Custom CSS rule
- If it’s crossed out, another rule is overriding it (add
!important) - If it’s not there at all, check for syntax errors or wrong selector
- In the Computed tab, see the final calculated value for each property
✅ Quick Reference: Custom CSS Essentials
| Concept | Key Takeaway |
|---|---|
| Where to find it | WhoKnew → WhoKnew Views → Styling tab → Scroll to bottom → 💻 Custom CSS |
| Four key selectors | .product-views-counter, .view-counter-wrapper, .view-counter-icon, .view-counter-text |
| !important flag | Use it on almost every rule to override plugin dropdowns |
| Per-product targeting | .postid-123 .selector { ... } (123 = product ID) |
| Category targeting | .product_cat-electronics .selector { ... } |
| Testing workflow | DevTools → Add rule → Test → Copy → Paste to Custom CSS box → Save |
| Common mistakes | Missing !important, wrong selector, syntax errors, !important in keyframes |
| Debugging | Inspect element → Styles panel → Check if rule is crossed out or missing |