Editing the default bundled theme directly inside a live PolyCMS installation guarantees painful merge conflicts the moment a module update arrives. Worse, leaking Perfex CRM staff Bootstrap rules into public pages ruins mobile layout control and drags down Lighthouse performance.
Building a dedicated custom theme inside modules/poly_cms/themes/ isolates your brand templates, CSS design tokens, and widget areas cleanly so PolyCMS core upgrades remain non-destructive.
Extending theme capabilities with custom data queries or hooks? See PolyCMS Hooks & Filters – Complete Reference before writing business logic inside views.
| Theme File / Folder | Purpose | Engineering Standard |
|---|---|---|
theme.json / Manifest | Declares name, slug, version, screenshot, and menus | Unique lowercase slug matching folder name |
views/layouts/ | Master shell: header, footer, meta, and main slot | Outputs clean HTML5 semantic landmarks |
views/pages/ & posts/ | Single post, archive, category, and 404 templates | Escapes dynamic fields via html_escape() |
assets/css/ & assets/js/ | Scoped stylesheet tokens and deferred frontend JS | Zero CRM admin CSS bleed; minified for production |
functions.php | Registers menu locations, sidebars, and theme hooks | Guarded with Perfex BASEPATH check |
1. Scaffold the Theme Directory and Manifest Contract
Create a dedicated folder under the PolyCMS themes directory using a clean lowercase slug such as acme_brand. Include a complete manifest describing theme metadata, supported menu locations, sidebar zones, and preview thumbnail so the PolyCMS Theme Manager recognizes and activates your package cleanly. Keep reusable business logic out of theme templates by placing non-visual features in extensions per Building a Custom Plugin for PolyCMS – Scaffold Guide.
- Add
defined('BASEPATH') or exit('No direct script access allowed');at the top of every standalone PHP file. - Define explicit navigation slots (for example
primary_navandfooter_nav) and widget sidebars inside your theme bootstrap. - Provide a crisp
screenshot.png(recommended 1200×900) so admins identify the theme immediately in PolyCMS Appearance.
2. Wire Template Hierarchy, SEO Hooks, and Scoped Assets
Every theme layout must emit required head and footer hook points so PolyCMS SEO tags, JSON-LD graphs, XML sitemap metadata, and plugin scripts inject automatically. Enqueue CSS tokens and deferred JavaScript strictly through theme asset helpers rather than hardcoding static links across partial views. When templating e-commerce product pages, align URLs and canonicals with E-Commerce SEO & GEO in Perfex CRM: PolyStore Variant URLs, Sitemaps & Schema.
- Render SEO title, meta description, canonical tag, and structured JSON-LD cleanly inside the theme
<head>hook slot. - Use explicit
widthandheightattributes on logos and featured thumbnails to hold CLS at zero. - Support Light and Dark color modes cleanly using CSS custom properties with WCAG AA text contrast.
Common Pitfalls and Quick Fixes
- Theme does not appear in PolyCMS Appearance list: Verify the folder name matches the manifest slug and contains valid JSON syntax without trailing commas.
- SEO meta tags or analytics scripts missing on frontend: Confirm your master layout invokes both the PolyCMS head and footer action hooks.
- 404 errors on custom post or archive templates: Check template filenames against the PolyCMS template hierarchy and ensure a fallback
404.phpview exists.
Frequently Asked Questions
Will upgrading PolyCMS overwrite my custom theme directory?
No, as long as you create a new folder with your own unique theme slug instead of modifying the bundled default theme files. PolyCMS upgrades update core controllers and bundled assets while leaving custom theme directories untouched inside the themes folder.
Should custom integrations or database tables live inside a PolyCMS theme?
No. Keep custom database tables, payment webhooks, CRM automations, and REST endpoints inside a PolyCMS plugin rather than a theme. Separating logic from presentation lets your team redesign or switch frontend themes later without losing operational features.
Can a custom PolyCMS theme support MTBuilder visual page layouts?
Yes. When your page template renders the main content region through PolyCMS content helpers and exposes clean container wrappers, MTBuilder rows, columns, and custom blocks inherit your theme typography and spacing tokens automatically.
How do I prevent broken asset URLs when deploying across staging and production?
Always resolve theme stylesheet, script, and image paths using PolyCMS theme URL helper functions instead of hardcoding domain names or root paths. Helper-generated URLs adapt seamlessly across local subfolders, staging domains, and production HTTPS hosts.

Leave a Reply