Where to put custom CSS and JavaScript

Customization 6 min read

You want to change something the settings do not cover, and you have a few lines of CSS or a script to add. Where those lines go decides whether they survive your next theme update.

#The short answer

A few lines of CSS go in AppearanceCustomizeAdditional CSS. Anything larger, and anything involving JavaScript, goes in a child theme.

Never edit the theme files. An update replaces them, and your changes go with it, silently and completely.

Custom code is yours, and so is what it does.

The moment you add CSS, JavaScript or PHP of your own, that code is outside support. We answer questions about the theme behaving as documented; we do not debug a rule you wrote, and a child theme does not change that. If something on your site breaks, the first question is what happens with your custom code removed.

Customizing the code: limits and responsibilityRead this before you open a file. A change to the code moves responsibility for the consequences to whoever made it. If something stops working after your own edits, that is not a support ca...Customization

If you would rather not write it yourself, that is a paid service rather than a support ticket, and it is quoted separately.

Custom work and paid customizationSupport covers the product working as documented. Anything beyond that is custom work, which we do take on, under separate terms. Most requests that arrive as "I need custom work" are not cu...Support

#The four places

Additional CSS in the Customizer

A handful of CSS rules. The fastest route, with a live preview, and the one that needs no files.

A child theme

CSS of any size, JavaScript, template overrides and PHP. The right home for anything the Customizer box has outgrown.

A site specific plugin

PHP that is about your site rather than its design, such as a shortcode or a redirect. It is the only one of the four that survives changing theme.

The theme files

Nothing. Ever.

What each one survives:

Where Theme update Theme change
Additional CSS yes no
Child theme yes no
Site specific plugin yes yes
Theme files no no

The last row is the one that matters. Editing style.css or a template inside the parent theme works until the day you update, and then it is gone with no warning and no copy.

#Additional CSS

WordPress ships a CSS box in the Customizer. Open AppearanceCustomizeAdditional CSS and type into it. The preview updates as you type, so you can see the rule land before you save.

It is right for overriding a color, adjusting spacing on one element, or hiding something the settings do not have a switch for.

Know its limits up front. It holds CSS only, it is stored per theme so switching theme leaves it behind, and it has no syntax checking, so one missing brace can break every rule after it. If your CSS box is over a hundred lines or so, it has outgrown the box.

Find the class with the browser inspector before writing anything.

Right click the element, choose Inspect, and read the class names on it. Guessing at selectors is where most of the time goes.

#A child theme

A child theme is a small theme of your own that inherits everything from the real one. Your files sit in a separate folder, so the parent can update as often as it likes and nothing of yours is touched. It is a standard WordPress mechanism, and our themes are built to be extended through it: filters, actions and overridable templates are there so a child theme rarely has to copy much. The theme dashboard can generate one for you, so you do not have to build the folder by hand.

This is the right home for a stylesheet longer than the Customizer box comfortably holds, for any JavaScript, and for changing a template rather than restyling it.

Child themes, template overrides and hooksEverything here survives updates. That is the reason to use these routes rather than editing files directly. Getting a child theme A child theme is not shipped in the package. The download c...Hooks & Filters

#JavaScript, and why it does not go in the CSS box

The Customizer CSS box stores CSS. It will not run a script, and pasting one there does nothing.

There are two correct routes.

Enqueue it from a child theme. Put the file in the child theme folder and register it in the child theme's functions.php, so WordPress loads it in the right order alongside everything else.

add_action( 'wp_enqueue_scripts', function () {
	wp_enqueue_script(
		'my-custom-script',
		get_stylesheet_directory_uri() . '/js/custom.js',
		array(),
		'1.0.0',
		true
	);
} );

Or use a snippet plugin, which is the better route for anything you did not write, such as an analytics or chat tag, because it keeps the snippet with the site rather than with the theme. Free ones in the plugin directory that do this job: WPCode for head and footer tags, Code Snippets for PHP snippets with an on and off switch on each.

Those are ordinary third party plugins, not integrations of ours, so they come with the usual condition: what they do on your site is yours to own.

Third party plugins and where responsibility sitsA site running one of our themes has two kinds of plugin, and they are different things. An integration A first-party package we wrote, for our themes, usually to replace a general-purpose p...Best Practices

#Why not the theme editor in the admin

The file editor at AppearanceTheme File Editor edits live files with no undo and no copy.

A syntax error there takes the whole site down, including the admin screen you would use to fix it. Many hosts disable it for exactly that reason, and if yours has not, treat it as read only.

#Common questions

Does support cover the CSS I wrote?

No. Support covers the theme working as documented, and code you added is outside it wherever it lives, including in a child theme. We will confirm whether a problem is still there with your custom code removed, because that answers who owns it.

My CSS is being ignored

Usually this is a specificity problem: some other rule is more specific and wins. Inspect the element, find the rule that is winning, and write a selector at least as specific. Reach for !important last, because it makes the next override harder for the same reason.

I changed the CSS and the site looks the same

Clear your caching plugin and any cache at your host or CDN, then load the page in a private window, which rules out your own browser in one step.

Will Additional CSS come with me to a new theme?

No. It is stored per theme, so a new theme starts with an empty box. Copy the contents out before switching.

Can I put custom code in a plugin instead?

Yes. For PHP that is not about appearance it is the better choice, because a site specific plugin survives changing theme while a child theme does not. Design code still belongs with the design.

It still is not working

Check whether the rule appears at all in the inspector. A rule that shows but is crossed out is being overridden, which is a selector problem. A rule that does not appear at all never loaded, which is a caching problem or a syntax error earlier in the file. Those are two different searches, and telling them apart first saves the most time.

#Still stuck

Open a support ticket and say what you tried and where it stopped. Your product, your domain, a screenshot and the exact message you saw are usually enough to settle it in one reply.

Last updated

Was this article helpful?

Related articles

FIND THE ONE THAT FITS YOUR PROJECT

Import a demo, swap the content, adjust the layout. Modern WordPress under the hood, fast even when the site fills up.