Creating a Theme

A jekcms theme is a folder of PHP and CSS files. There is no build step, framework or generator: the router requires your template, and the template's output becomes the page.

The Themes screen, which draws its list from the registered theme set
A folder that is not in the registry does not appear here, even if its theme.json is correct.

Before you start, note one limitation. The Themes screen renders from a fixed registry of known theme slugs. A new folder in /themes/ is not picked up by the admin panel, and there is no ZIP upload and no way to register a slug from the UI, so a theme you write yourself cannot be offered or activated through Appearance → Themes. New themes reach an install through the signed update channel instead.

This page therefore explains how the theme layer works. It helps you read the shipped themes, edit a copy in a development install, or build a theme that will be distributed with the product. It does not describe a way to install your own theme on a customer site.

Anatomy

themes/my-theme/
  theme.json          manifest and customizer schema
  functions.php       loaded automatically on every request
  activate.php        optional, runs once when the theme is activated
  screenshot.png      card image
  templates/
    header.php  footer.php
    index.php   single.php  page.php  archive.php  search.php
    errors/404.php
  partials/
    post-card.php  pagination.php  sidebar.php  comments.php
  sections/
    hero.php  latest.php
  assets/
    css/style.css

Only templates/index.php is required, because the activation check parses it. The other files follow conventions that the router and the layout engine rely on.

The manifest

{
    "name": "Ocean",
    "slug": "ocean",
    "version": "1.0.0",
    "author": "Your Name",
    "description": "A clean coastal theme.",
    "screenshot": "screenshot.png",
    "supports": { "card_options": true, "share_styles": true }
}

The slug the system uses is always the folder name; the slug key in the file is only documentation and is never read. See the theme.json reference for the keys that have an effect.

How the router picks a template

Templates live under templates/, and the router requires them by name against the active theme: index.php for the homepage, single.php for a post, page.php for a page, archive.php for category, tag, author and date archives, search.php for search results. Error pages resolve as templates/{code}.php first and templates/errors/{code}.php second, so 404.php can live in either place.

The router does not load header.php and footer.php. Templates include them themselves, so every shipped template starts and ends the same way:

<?php
require_once dirname(__DIR__) . '/functions.php';
include __DIR__ . '/header.php';
// …
include __DIR__ . '/footer.php';

What is in scope

The router passes only a few values to templates, through $GLOBALS instead of local variables. On a post or page, $GLOBALS['post'] holds the full row joined with the author's name, slug and avatar. On an archive, $GLOBALS['archive_type'] and $GLOBALS['archive_slug'] say which archive you are on, with archive_year and archive_month on date archives.

On the homepage, no values are passed. templates/index.php queries the data it needs. There is no $GLOBALS['posts']: every shipped theme builds its own list, so archive templates start with their own SELECT.

<?php
require_once dirname(__DIR__) . '/functions.php';

$post = $GLOBALS['post'] ?? null;
if (!$post) { http_response_code(404); /* … */ return; }

include __DIR__ . '/header.php';
?>
<article class="post">
    <h1><?= e($post['title']) ?></h1>
    <div class="post-content"><?= render_content($post['content']) ?></div>
</article>
<?php include __DIR__ . '/footer.php'; ?>

Use e() for escaping; it is the project's short form of htmlspecialchars.

The head

Most product features add their output to the page through a theme's header.php. The shipped set calls, in order: get_meta_title() for the <title>, output_robots_meta() for the indexing directives, output_canonical_tag(), output_theme_custom_fonts() for the fonts the customizer selected, theme_asset() for the stylesheet, output_theme_customization_css() for the generated CSS variables, then output_og_tags(), output_schema(), output_favicon_tags() and output_seo_head().

Without output_theme_customization_css(), no customizer setting reaches the page, because every colour, font, width and studio setting is printed by that one call. Without output_robots_meta(), post-level indexing rules stop working, and no error is shown.

Content is rendered with the theme's own render_content(), not by printing $post['content']. This function resolves shortcodes, inserts in-content boxes and adds lazy loading.

functions.php

The active theme's functions.php is loaded automatically on every request, and templates also require it themselves, so it is available even when a template is included in another way. By then three constants are defined: THEME_PATH, THEME_URL and THEME_VERSION.

Each theme defines its own small set of helpers in this file instead of inheriting them: theme_asset() (prefixes assets/ and appends a filemtime cache buster), theme_config() and theme_setting() (read the static settings block of theme.json), theme_supports(), render_content(), render_pagination() and get_body_classes(). If you copy a theme, copy its functions.php too, because these are not core functions.

Partials and sections

partials/ holds the pieces you reuse: a post card, pagination, a sidebar, the comment block. Include them directly. A partial uses the caller's scope, so $post inside a foreach is available without passing it.

sections/ works differently. These files are the homepage blocks that users can reorder and switch off in the customizer. The layout engine renders them; they are not included in a fixed order. A theme's index.php asks the engine to draw the page and falls back to a default sequence only if the engine is unavailable.

The most important rule here: an included file runs in the caller's scope. A partial that assigns a value to $post, $posts, $categories, $tags or $counts overwrites the calling template's variable without any error, and the resulting bug is very hard to find. Give every variable a partial creates a prefix.

Hooks

do_action('wp_head') and do_action('wp_footer') exist and work. The core uses wp_footer for the integrity watermark and the analytics trackers. They are optional, and most shipped themes do not call them; three do. If your theme is meant to host third-party snippets, call both.

Note that apply_filters() exists as a stub and returns its input unchanged. Do not rely on it.

Next

Once your theme renders, give it a customizer schema so its colours, fonts and layout become editable without touching files: Theme customization explains the mechanism, and the theme.json schema lists every key.

Be the first to know

New features, release notes and CMS guides. We send a couple of emails a month.