wordpress code Archives - Duplicator https://duplicator.com The Best WordPress Backup and Migration Plugin Thu, 26 Jun 2025 12:00:00 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.4 https://duplicator.com/wp-content/uploads/2023/04/cropped-favicon-32x32.png wordpress code Archives - Duplicator https://duplicator.com 32 32 Transform Your Site from Static to Dynamic with WordPress JavaScript https://duplicator.com/wordpress-javascript/?utm_source=rss&utm_medium=rss&utm_campaign=wordpress-javascript Thu, 26 Jun 2025 12:00:00 +0000 https://duplicator.com/?p=982896 Need your WordPress site to do more than just display content? This post will show you how WordPress JavaScript adds dynamic content to engage your visitors!

The post Transform Your Site from Static to Dynamic with WordPress JavaScript appeared first on Duplicator.]]>
Ever visited a website where elements move, change, or respond to your clicks without reloading the page? That’s JavaScript in action.

While WordPress is built on PHP, JavaScript has become essential for creating modern, interactive websites that users love.

Whether you’re looking to add simple animations or build complex features, JavaScript opens up a world of possibilities.

In this post, I’ll explain what JavaScript is and why you might want to start learning it. You’ll also find out how to add custom JavaScript in WordPress!

Table of Contents

What Is JavaScript?

JavaScript is a programming language that runs in your visitors’ browsers, not on your server.

When someone visits your WordPress site, the server processes PHP code and sends HTML and CSS to their browser. Then JavaScript takes over, allowing real-time interactions without sending more requests to the server.

Here are some common things JavaScript handles on WordPress sites:

  • Showing or hiding content when a button is clicked
  • Validating form fields before submission
  • Loading new content without refreshing the page
  • Creating animations and visual effects
  • Updating parts of a page based on user input

Unlike PHP changes that require server processing, JavaScript can make your site feel responsive and app-like because it happens instantly in the user’s browser.

Why Learn WordPress JavaScript?

JavaScript skills have become increasingly valuable, and for good reason.

Adding JavaScript to your WordPress toolkit lets you create better user experiences by making your site feel faster and more responsive.

It can also solve front-end problems that PHP simply can’t address. While PHP handles server operations beautifully, it can’t directly respond to mouse movements or update content dynamically.

With JavaScript, you’ll be able to customize existing themes and plugins without completely rebuilding them. Often, a small JavaScript tweak can modify functionality without diving into complex PHP code.

Knowing JavaScript helps you stay relevant in WordPress development. With the block editor (Gutenberg) built on React (a JavaScript framework), JavaScript has become essential for serious WordPress developers.

You can also build custom solutions with JavaScript that plugins can’t provide. When you need something uniquely tailored to your site’s needs, JavaScript gives you the freedom to create it.

Where to Learn WordPress JavaScript

Start with core JavaScript fundamentals before diving into WordPress-specific applications. You wouldn’t build a house without understanding the materials, and the same applies here.

Good resources for JavaScript basics include:

  • freeCodeCamp
  • Mozilla Developer Network JavaScript tutorials
  • Codecademy’s JavaScript course

Once you’ve grasped the fundamentals, move to WordPress-specific JavaScript resources.

The official WordPress Developer Handbook has sections dedicated to JavaScript. It’ll teach you proper script loading with wp_enqueue_script() and working with the WordPress JavaScript API.

Learn.wordpress.org offers workshops on JavaScript development. WPBeginner and CSS-Tricks both publish excellent WordPress JavaScript tutorials, too.

And here’s an extra (often overlooked) tip: see how quality themes and plugins use JavaScript. WordPress code is open source, giving you real-world examples to study.

How to Add Custom JavaScript to WordPress

There are several ways to add JavaScript to your WordPress site, each with different use cases. Let’s look at some common methods.

1. Use a JavaScript WordPress Plugin

For beginners, WordPress code plugins provide the safest entry point. Manually adding JavaScript code can be difficult, and I’d only recommend it to developers.

WPCode (formerly Insert Headers and Footers) lets you add JavaScript snippets without touching theme files. This is a perfect example of a WordPress JavaScript plugin that simplifies code management.

Here’s some benefits of using WPCode to add JavaScript:

  • Your code remains intact during theme updates, unlike direct file editing.
  • You can easily disable scripts without removing code when troubleshooting.
  • The plugin handles proper code placement in either the header or footer.
WPCode plugin

I personally use this method when testing new scripts or implementing quick fixes on client sites. It provides a safety net while still getting the job done.

To get started, install and activate WPCode. Then, add a new custom snippet.

Add a custom code snippet in WPCode

For the Code Type, choose JavaScript Snippet. Enter your JavaScript into the code editor.

WPCode JavaScript snippet

Save the JavaScript code snippet. If you want WPCode to handle placement for you, scroll down to Insertion and click Auto Insert.

WPCode auto insert snippet

However, feel free to change the location to a specific post or page.

WPCode also gives you options for conditional loading (showing scripts only on certain pages), which helps with performance optimization. All you’ll need to do is enable the logic and choose the conditions.

Enable conditional logic for code snippet

If you’re ready to activate the snippet, scroll back to the top and turn on the toggle switch.

Activate JavaScript snippet

Hit Update and you’re done! You just added custom JavaScript without needing any development experience.

2. Edit Your Theme’s functions.php File

The functions.php file is where WordPress handles its programmatic functionality, including script management.

Adding JavaScript through your WordPress theme’s functions file gives you more control and eliminates the need for extra plugins.

However, you should NEVER edit your parent theme’s functions.php file directly. These changes will be lost when the theme updates.

Always use a child theme for any code modifications. This is essential for maintaining your customizations long-term.

Once you have a child theme activated, go to Appearance » Theme File Editor and open the functions.php file.

Theme functions file in WordPress

WordPress provides a standardized function for adding JavaScript properly: wp_enqueue_script(). This isn’t just a suggestion—it’s the WordPress way of managing scripts.

Using this method helps:

  • Prevent conflicts between different scripts
  • Manage loading order when one script depends on another
  • Handle version control for browser caching
  • Optimize placement in your page’s HTML

Here’s a basic example of how to add custom JavaScript to your WordPress site:

function my_custom_scripts() {

wp_enqueue_script(

'my-custom-script', // Unique handle

get_stylesheet_directory_uri() . '/js/my-script.js', // File path

array('jquery'), // Dependencies

'1.0', // Version number

true // Load in footer (recommended)

);

}

add_action('wp_enqueue_scripts', 'my_custom_scripts');

The parameters break down as:

  • A unique name (handle) for your script
  • The location of your JavaScript file
  • Any dependencies your script needs
  • Version number (helps with browser caching)
  • Whether to place in the footer (true) or header (false)

Loading scripts in the footer (parameter #5 set to true) improves page loading performance by letting visible content load first. Using WordPress hooks like wp_enqueue_scripts ensures your code runs at exactly the right time in the page loading process.

JavaScript Tips and Troubleshooting

Even experienced developers encounter issues when adding JavaScript to WordPress. Here are some practical tips to avoid common problems.

Always use wp_enqueue_script() instead of hardcoding <script> tags. This prevents conflicts with other plugins and themes.

Check your browser’s developer tools for JavaScript errors. If you find your WordPress JavaScript not working as expected, the console will usually provide clues about what’s going wrong.

When scripts aren’t working, verify that dependencies are loading correctly. If your code needs jQuery but loads before it, things will break.

Place scripts in the footer whenever possible by setting the last parameter of wp_enqueue_script() to true. This improves page load performance and prevents scripts from trying to manipulate elements that haven’t loaded yet.

Wrap your JavaScript in immediately invoked function expressions (IIFE) to avoid conflicts with other scripts:

(function($) {
    // Your code here
    $('.my-button').click(function() {
        // Button click code
    });
})(jQuery);

Use unique variable and function names to prevent collisions with other scripts. Prefixing with your theme or plugin name helps.

Remember that WordPress includes jQuery in “no-conflict” mode. Always use jQuery() instead of $() unless you’re wrapping your code as shown in the IIFE example above.

WordPress JavaScript Examples

JavaScript can do a ton of cool stuff for your WordPress site. Here are just a few examples to show you what’s possible.

Fade Page Transitions

Remember when I said JavaScript can add animations to your website? One thing you can do is make your page fade away when someone clicks on a link.

WPCode has a pre-made JavaScript code snippet for this! Simply search for Fading Page Transitions in the Code Snippets library.

WPCode fade transitions snippet

Or, paste this code into a new custom snippet:

document.addEventListener("DOMContentLoaded", function() {
    // Create and insert CSS styles for fade-in and fade-out
    const style = document.createElement('style');
    style.innerHTML = `
        .fade-out {
            opacity: 0;
            transition: opacity 0.5s ease-in-out;
        }
        .fade-in {
            opacity: 1;
            transition: opacity 0.5s ease-in-out;
        }
    `;
    document.head.appendChild(style);

    // Apply the fade-in effect on page load
    document.body.classList.add('fade-in');

    // Attach event listeners to all internal links for the fade-out effect
    document.querySelectorAll('a').forEach(anchor => {
        anchor.addEventListener('click', function(event) {
            if (anchor.hostname !== window.location.hostname) return;

            event.preventDefault();
            const target = this.href;

            document.body.classList.remove('fade-in');
            document.body.classList.add('fade-out');

            setTimeout(function() {
                window.location.href = target;
            }, 500); // Match this duration with the CSS transition time
        });
    });
});

Disable Content Copying

If you need to protect your premium content from easy copying, you can use this script:

document.addEventListener("contextmenu", (evt) => {

evt.preventDefault();

}, false);

document.addEventListener("copy", (evt) => {

evt.clipboardData.setData("text/plain", "You must pay a premium subscription to copy our content");

evt.preventDefault();

}, false);

Add Smooth Scrolling

Another feature you can add to your WordPress website with JavaScript is smooth scrolling. This web effect uses scroll actions to create a much more pleasant navigation experience for users.

Here’s the JavaScript for smooth scrolling:

document.addEventListener('click', function(e) {

// Check if the clicked element is an anchor with href starting with '#'

if (e.target.tagName === 'A' && e.target.getAttribute('href') && e.target.getAttribute('href').startsWith('#')) {

e.preventDefault();

const targetId = e.target.getAttribute('href').slice(1); // Remove the '#' from the href

const targetElement = document.getElementById(targetId);

if (targetElement) {

targetElement.scrollIntoView({

behavior: 'smooth'

});

}

}

});

Frequently Asked Questions (FAQs)

Does WordPress use PHP or JavaScript?

WordPress uses both PHP and JavaScript, but for different purposes. PHP powers the server-side operations—the content management system, database interactions, and most of the WordPress core functionality. When you save a post or change settings, PHP handles those operations.

JavaScript handles client-side interactions—what happens in the visitor’s browser after the page loads. This includes animations, interactive elements, real-time validation, and dynamic content changes without page reloads.

Modern WordPress development, especially with the block editor (Gutenberg), increasingly relies on both languages working together.

What is replacing JavaScript?

Nothing is directly replacing JavaScript. As the only native programming language supported by all web browsers, JavaScript remains fundamental to web development.

How can I add JavaScript to WordPress without a plugin?

The most common plugin-free method to add JavaScript to WordPress is through your child theme’s functions.php file using WordPress’s wp_enqueue_script() function. For one-off cases, you could also use a page builder’s custom code feature if your theme provides one.

Remember that avoiding plugins isn’t always better—a well-maintained plugin often handles edge cases and updates better than custom code.

Can you use JavaScript to build a website?

Yes, JavaScript can be used to build entire websites and web applications, especially with modern frameworks like React, Vue, or Angular.

In WordPress specifically, JavaScript enhances the existing PHP/HTML/CSS foundation rather than replacing it. You’re adding JavaScript functionality to a WordPress core that’s primarily PHP-based.

For example, the WordPress block editor (Gutenberg) is built with React (a JavaScript framework) but still operates within the PHP-based WordPress ecosystem.

How do I add JavaScript to a specific WordPress page?

The easiest way to add JavaScript to WordPress pages is with WPCode. Add a new custom JavaScript snippet. Scroll down to Location and expand the dropdown menu. Select Page-Specific, and then decide where you want your JavaScript to apply.

WPCode page-specific snippet

This approach works equally well for both WordPress pages and posts, giving you granular control over where your scripts run.

Final Thoughts

Adding JavaScript to your WordPress toolkit dramatically extends what you can do with your website.

From simple interface enhancements to complex interactive features, JavaScript bridges the gap between static content and dynamic user experiences.

Always remember that mistakes happen. Before adding JavaScript or making any significant changes, create a complete backup of your site.

Duplicator Pro makes it easy to back up your website on a schedule. Plus, it gives you simple restore options if something goes wrong. Try it out today!

Your JavaScript journey with WordPress doesn’t end here — it’s a continuously evolving field as both JavaScript and WordPress grow. Investing in learning JavaScript will significantly benefit your own projects and client work!

While you’re here, I think you’ll like these other WordPress guides:

The post Transform Your Site from Static to Dynamic with WordPress JavaScript appeared first on Duplicator.]]>
Learning WordPress CSS: Simple Techniques I Wish I’d Known From Day One https://duplicator.com/wordpress-css/?utm_source=rss&utm_medium=rss&utm_campaign=wordpress-css Mon, 12 May 2025 12:00:00 +0000 https://duplicator.com/?p=978519 Too limited by your WordPress theme's options? This guide shares WordPress CSS techniques — simple solutions to customize your site exactly how you want it!

The post Learning WordPress CSS: Simple Techniques I Wish I’d Known From Day One appeared first on Duplicator.]]>
Have you ever stared at your WordPress site thinking, “It’s so close to perfect, but that button is the wrong shade of blue,” or “I wish I could make that text a bit larger”?

WordPress themes come with customization options, but sometimes they can’t cover everything you might want to change.

That’s where CSS comes in — it’s like having a magic wand that lets you tweak your site’s appearance exactly how you want it.

In this guide, I’ll walk show you what CSS is, how to add your own custom styles, and some practical examples to get you started.

By the end, you’ll feel more comfortable making those visual adjustments that take your site from “almost there” to “exactly right.”

What Is CSS?

Think of your WordPress website like a house. The HTML code forms the structure — the walls, rooms, and foundation. CSS (Cascading Style Sheets) is all the interior design elements: the paint colors, furniture arrangement, lighting, and decorative touches.

CSS tells your browser how to display the content on your page. Want all your paragraph text to be blue? CSS can do that.

Need more space between your heading and the paragraph below it? CSS handles that too.

The basic structure of CSS follows this pattern:

selector { property: value; }

The selector targets specific elements on your page, and the property-value pairs define how those elements should look.

For example:

p { color: blue; }

This simple line tells the browser to display all paragraph text in blue. That’s all there is to it!

While simple in concept, CSS becomes powerful when you start combining different selectors and properties to create precise styling rules for your site.

Where Does CSS Live in WordPress?

CSS in WordPress isn’t just in one place — it’s layered throughout your site, which is why it’s called “cascading.” Understanding this hierarchy helps you know where to make changes.

Your theme’s style.css file is the foundation. It contains all the basic styling rules that give your theme its signature look. Think of it as the default interior design package.

The WordPress Customizer offers a dedicated “Additional CSS” section where you can safely add your own styles. These override the theme’s defaults and survive theme updates.

If you’re making substantial changes, a child theme is your best bet. Its style.css file inherits everything from the parent theme, but any styles you add take precedence.

Some plugins bring their own CSS to style their specific features. These usually load after theme styles.

The Block Editor (Gutenberg) and Full Site Editor introduce new ways to add CSS, allowing you to style specific blocks or sections without affecting the entire site.

Occasionally, you’ll see inline CSS — styles applied directly to HTML elements using the style attribute. This approach is generally discouraged for sitewide styling because it’s harder to maintain.

Understanding this cascade is important because when styles conflict, the more specific or later-loading CSS wins. This is why you can override your theme’s styling with custom CSS.

Why Learn WordPress CSS?

Learning CSS gives you control that theme options alone can’t provide.

Many WordPress users hit a frustrating wall when they can’t change something about their site’s appearance. The color picker doesn’t have quite the right shade. The spacing between elements looks off. The font size needs to be just a bit larger.

With even basic CSS knowledge, you can make these precise adjustments yourself.

CSS allows you to make your site truly unique. Without it, you’re limited to whatever customization options your theme developer thought to include. With CSS, you can break free from those constraints.

When visual glitches appear (and they will), understanding CSS helps you fix them quickly. Maybe a plugin update caused some text to overlap, or a theme update changed your button styling. A few lines of CSS can often solve these issues immediately.

Most importantly, learning CSS builds a foundation for understanding how WordPress themes work. Once you grasp how CSS controls appearance, you’ll better understand why things look the way they do — making troubleshooting much faster.

Where to Learn WordPress CSS

There are plenty of accessible resources available to learn CSS, many of them free.

Mozilla Developer Network (MDN) Web Docs is a great resource for web technologies including CSS. Their tutorials break down concepts into digestible pieces with practical examples.

W3Schools offers beginner-friendly CSS lessons with interactive examples where you can test code directly in your browser. This hands-on approach makes learning feel less abstract.

YouTube is filled with tutorials specifically for WordPress CSS. Seeing someone walk through changes in real time can help concepts click when text explanations aren’t enough.

Many course platforms like Coursera and Udemy offer free (or very affordable) CSS courses. Some focus specifically on WordPress, showing you exactly how to target theme elements.

The most effective learning happens when you actually practice. Set up a test site (don’t experiment on your live site!) and try making small changes. See what happens when you adjust properties like colors, margins, or font sizes.

Remember that you don’t need to memorize every CSS property. Even professional developers regularly look things up. Understanding the core concepts is what matters.

How to Add Custom CSS to WordPress

WordPress offers several ways to add custom CSS. Each has its advantages depending on your needs and comfort level.

Add Custom CSS Using the Theme Customizer

The WordPress Customizer is the safest place to easily add CSS to WordPress.

Navigate to Appearance » Customize » Additional CSS in your WordPress dashboard.

WordPress Customizer Additional CSS

You’ll see a code editor where you can type or paste your CSS.

Edit CSS in Customizer

You can preview your changes in real time before publishing them. If something doesn’t look right, adjust your code and immediately see the results.

The Customizer is perfect for small to medium amounts of CSS. If you find yourself adding hundreds of lines of code, you might want to consider one of the other methods.

Add Custom CSS Using a Plugin

WPCode (formerly Insert Headers and Footers) is a popular code snippets plugin. It provides a more organized way to manage your custom CSS.

WPCode plugin

After installing the plugin, navigate to Code Snippets » Add Snippet. Hover over Add Your Custom Code and click on Add Custom Snippet.

WPCode add custom snippet

Choose CSS Snippet as the code type, give it a descriptive name, and add your CSS code.

WPCode CSS snippet

WPCode offers several advantages over the Customizer. You can create multiple CSS snippets, making them easier to manage than one large block of code.

You can also control precisely where and when snippets run. Need CSS that only applies to your blog posts? WPCode can handle that conditional loading.

The plugin includes error prevention features that help catch syntax mistakes before they affect your live site — a helpful safety net when you’re learning.

Add Custom CSS with the Full Site Editor

If you’re using a block theme, you have access to the Full Site Editor instead of the Customizer. However, you can still add custom CSS to your site.

Navigate to this URL, adjusting it with your site’s domain: https://example.com/wp-admin/customize.php

This will open a limited version of FSE. You’ll see that it has an Additional CSS section, just like the Customizer.

Edit Theme Files

For extensive customizations, you might need to edit CSS in WordPress theme files directly.

In your dashboard, you can go to Appearance » Theme File Editor and edit the style.css file.

WordPress style.css file in theme file editor

However, this comes with an important warning: I wouldn’t recommend modifying a parent theme’s files directly.

Instead, create a child theme. A child theme inherits all the functionality and styling of the parent theme while allowing you to safely make changes that won’t be overwritten during updates.

Once you have a child theme activated, you can edit the CSS files in your WordPress theme file editor. You could also access your theme files using FTP or your hosting provider’s file manager.

Common Custom CSS in WordPress

Let’s look at some practical examples of simple custom CSS that solve common WordPress customization needs.

Styling Gutenberg Blocks

Want to make your quote blocks stand out more? You can target them with CSS:

.wp-block-quote {

background-color: #f9f9f9;

border-left: 4px solid #0073aa;

padding: 20px;

}

This gives the quote blocks a light gray background, a blue left border, and some padding for breathing room.

Styling Widgets

Maybe your sidebar widgets need some visual separation. You can add space and borders between them:

.widget {

margin-bottom: 30px;

padding-bottom: 20px;

border-bottom: 1px solid #eaeaea;

}

Each widget will now have more space below it and a subtle dividing line.

Customizing Navigation Menus

Navigation menus often need styling adjustments to match your site’s design:

.main-navigation li a {

color: #333333;

font-weight: 500;

text-transform: uppercase;

}

.main-navigation li a:hover {

color: #0073aa;

}

This makes menu links dark gray, slightly bold, all-caps, and blue when hovered over.

Changing Fonts and Typography

Typography has a huge impact on your site’s personality. Here’s an example of how you could customize fonts with CSS:

body {

font-family: 'Open Sans', sans-serif;

font-size: 16px;

line-height: 1.6;

}

h1, h2, h3 {

font-family: 'Montserrat', sans-serif;

font-weight: 700;

}

Remember that if you’re using non-standard fonts, you’ll need to import them first using @font-face or by linking to Google Fonts.

Modifying Colors and Backgrounds

Changing colors is one of the most common CSS tasks. These few lines change your site’s background to light gray and make links pink with a darker shade when hovered over:

body {

background-color: #f5f5f5;

}

a {

color: #e94c89;

}

a:hover {

color: #c13872;

}

Adjusting Spacing

The space around and within elements (margin and padding) significantly affects readability. This adds space below paragraphs and creates padding around your main content area:

.entry-content p {

margin-bottom: 20px;

}

.site-content {

padding: 40px 20px;

}

Styling Forms

Forms often need styling help to match your site’s design. These styles create clean form fields with a standout submit button:

input[type="text"],

input[type="email"],

textarea {

border: 1px solid #ddd;

padding: 10px;

border-radius: 4px;

}

input[type="submit"] {

background-color: #0073aa;

color: white;

padding: 12px 20px;

border: none;

border-radius: 4px;

}

CSS Tips and Troubleshooting

Even experienced developers run into CSS problems. Here are some common issues and how to solve them.

Browser Caching

You’ve added new CSS, but your site looks exactly the same. Before you panic, this is often just browser caching.

Browsers save (cache) CSS files to load sites faster. This means they might be showing you old CSS instead of your new changes.

Try a hard refresh by pressing Ctrl+F5 (Windows) or Cmd+Shift+R (Mac). This forces your browser to get fresh copies of all files instead of using cached versions.

WordPress Caching

If you use a caching plugin like WP Super Cache or W3 Total Cache, you’ll need to clear that cache too when making CSS changes.

Look for a Clear Cache button in your caching plugin’s settings.

Clear WordPress cache

Until you clear this cache, your changes might only be visible to you (when logged in) but not to regular visitors.

Selector Issues

When your CSS isn’t working, the problem often lies with the selector — you’re targeting the wrong element.

CSS follows a specificity hierarchy. More specific selectors override general ones. For example, #sidebar p (an ID plus an element) will override styles set just for p (an element).

Misspellings are easy to miss. Was it .sidebar or .side-bar? One hyphen makes all the difference.

Your browser’s developer tools are invaluable for troubleshooting. Right-click the element you’re trying to style and select Inspect. You’ll see all the styles currently applied and which ones are being overridden.

Chrome DevTools CSS code

Avoiding !important

The !important declaration forces a style to apply regardless of specificity:

p { color: blue !important; }

While tempting when you’re frustrated, !important creates long-term headaches. It breaks the natural cascading of CSS and leads to “specificity wars” where you end up needing multiple !important declarations.

Instead, make your selectors more specific. If .content p isn’t working, try .content .entry-content p to be more precise.

Testing Across Devices and Browsers

Your site needs to look good everywhere. What works on your laptop might break on mobile screens.

Use your browser’s developer tools to simulate different screen sizes. In Chrome, right-click, select Inspect, and look for the device toggle icon.

Chrome DevTools mobile view

Always Back Up Before Making Changes

Before diving into CSS changes, especially extensive ones, back up your site. This isn’t just good advice — it’s crucial protection.

Tools like Duplicator make backups straightforward. Simply create a new backup and choose the Full Site preset.

Full site backup preset

For extra protection against site-specific errors, I always send backups to the cloud. As you’re creating the backup, choose one of the many cloud storage integrations.

Backup storage locations

Having this safety net means you can experiment more freely, knowing you can restore everything if something goes wrong.

A five-minute backup can save you hours of troubleshooting. If you notice a CSS mistake, go to this backup and hit Restore.

Restore backup

Even if your backup is in the cloud, Duplicator will download it and restore it. It’ll be like that error never happened!

Frequently Asked Questions (FAQs)

How do I get CSS in WordPress?

CSS comes built into your WordPress theme. You can add your own custom CSS through the Customizer (Appearance » Customize » Additional CSS), with a WordPress code plugin like WPCode, or by creating a child theme and editing its style.css file.

Does WordPress use HTML or CSS?

WordPress uses both. HTML creates the structure of your pages and posts, while CSS controls how that structure looks. WordPress generates the HTML automatically based on your content, and your theme provides the CSS that styles it.

What are some custom CSS WordPress examples?

Here are a few simple examples of custom WordPress CSS:

  • Make text larger: p { font-size: 18px; }
  • Change button color: .button { background-color: #ff6b6b; }
  • Add space after images: .wp-block-image { margin-bottom: 30px; }
  • Hide an element: .element-to-hide { display: none; }
  • Make text bold: .special-text { font-weight: 700; }

Do I need to learn CSS for WordPress?

You don’t need to learn CSS if you’re satisfied with your theme’s built-in options. However, learning even basic CSS gives you much more control over your site’s appearance and the ability to fix visual problems without waiting for theme updates or paying a developer.

Do web developers use CSS?

Yes, CSS is one of the core technologies used by all front-end web developers, alongside HTML and JavaScript. It’s an essential skill for anyone building websites professionally.

Final Thoughts

CSS isn’t some mysterious code that only professional developers can understand. It’s a practical tool that gives you precise control over how your WordPress site looks.

Starting small is the key — change a color here, adjust some spacing there. As you get more comfortable, you’ll find yourself capable of making more complex adjustments.

Remember that every professional WordPress developer started exactly where you are now. They learned by experimenting, making mistakes, and gradually building their skills.

As you get started, keep a backup handy with Duplicator. It rolls back errors in one click, so if something doesn’t work, you can always revert your changes and try again.

While you’re here, I think you’ll like these other WordPress guides:

The post Learning WordPress CSS: Simple Techniques I Wish I’d Known From Day One appeared first on Duplicator.]]>
WordPress is Drag & Drop, BUT… Here’s Why I Still Mess with HTML https://duplicator.com/wordpress-html/?utm_source=rss&utm_medium=rss&utm_campaign=wordpress-html Thu, 24 Apr 2025 12:00:00 +0000 https://duplicator.com/?p=966794 Are you confused why anyone bothers with HTML when WordPress is drag & drop? I was too! Let me show you the surprising power HTML still holds!

The post WordPress is Drag & Drop, BUT… Here’s Why I Still Mess with HTML appeared first on Duplicator.]]>
Ever wondered how websites actually work?

It might seem like magic, but there’s a language behind every webpage you see. That language is called HTML.

Think of HTML as the basic building blocks of the internet.

Even just a little bit of HTML knowledge can really level up your WordPress game. I’ve seen firsthand how it helps people make their WordPress websites even better.

In this post, I’ll explain what HTML is, why it matters, and how you can add custom HTML code to your WordPress site.

You might be surprised how easy and helpful it can be for effective web design!

Table of Contents

What Is HTML?

HTML stands for HyperText Markup Language. Basically, HTML is the language that structures web content. Think of it as the skeleton of a webpage.

HTML uses something called “tags”. Tags tell the web browser what each part of your content is.

For example, tags can tell the browser that something is a heading, a paragraph, or an image. Browsers read these tags to display web pages the way they should look.

HTML isn’t a programming language. It’s more like a way to organize information so browsers can understand it.

Why Should You Care About HTML in WordPress?

WordPress is super easy to use. You can build a whole website without knowing any code. So, why bother with HTML?

Well, HTML gives you more control over your content. Sometimes the regular WordPress editor just isn’t enough.

Say you want to add a specific attribute to an image. Or maybe you want to create a really unique list style. HTML lets you do things like that.

HTML is also a lifesaver for troubleshooting.

Ever had a weird formatting issue in WordPress? Looking at the HTML can help you quickly find and fix the problem. It’s way faster than guessing with the visual editor.

Plus, HTML gives you flexibility. Want to add some advanced customizations? Like custom classes for styling or more complex layouts? HTML unlocks those possibilities.

And here’s a big one: future-proofing.

WordPress is always changing. But HTML? It’s a fundamental web skill that will always be useful.

I’ve seen it time and time again – understanding HTML makes you way more adaptable in the web world.

HTML 101: The Basics

Let’s talk about the building blocks of HTML. They’re called tags.

Tags are instructions that tell the browser what to do with your content. Most tags come in pairs: an opening tag and a closing tag.

For example, if you want to create a paragraph, you use the <p> tag to start it and </p> to end it.

See the slash in the closing tag? That’s how you know it’s the end.

Let’s look at some common HTML tags you’ll use a lot:

Headings are for titles and subheadings. You’ve got <h1>, <h2>, <h3>, <h4>, <h5>, and <h6>.

<h1> is the most important heading (usually the main title), and <h6> is the least important.

Links are what make the web, well, a web! The <a> tag creates links. <a> stands for anchor.

Want to show pictures? The <img> tag is your friend. <img> is short for image.

Need to make a list of things? HTML has you covered. There are two main types:

  • <ul> for unordered lists (bullet points). “ul” stands for “unordered list”.
  • <ol> for ordered lists (numbered lists). “ol” stands for “ordered list”.

And inside both <ul> and <ol>, you use <li> tags for each item in the list. “li” stands for “list item”.

Tags can also have attributes. Attributes give extra information about a tag.

For example, the <a> tag needs an href attribute to tell it where to link to. Like this: <a href="proxy.php?url=https://example.com">Link text</a>. The href attribute holds the website address.

And the <img> tag needs a src attribute to tell it where to find the image file. It also should have an alt attribute for “alternative text,” which is important if the image can’t load or for accessibility.

Like this: <img src="proxy.php?url=image.jpg" alt="Descriptive text">.

Here’s a super simple example of HTML in action:

<h1>Welcome to My Blog</h1>

<p>This is my first paragraph of content. It's going to be awesome!</p>

<a href="proxy.php?url=https://duplicator.com">Check out Duplicator!</a>

That code would create a main heading, a paragraph, and a link on a webpage.

When I first started learning HTML, these basic tags were my starting point. And honestly? They’re still the foundation of almost everything I do online. These simple tags are powerful!

Putting HTML to Work: Practical Examples

So, how can you actually use HTML in WordPress? Let’s look at some examples.

Want to make some text bold or italic? HTML can do that.

Use <strong> and </strong> tags to make text bold. Or use <b> and </b> tags, they also make text bold.

Like this: <strong>This text is bold</strong>.

For italics, use <em> or <i>. Like this: <em>This text is italic</em>.

These tags help you emphasize words and phrases in your content.

We talked about the <a> tag. You can use it to link to other pages on your site, or to other websites.

You can link text, images, or even buttons. It’s all about using that <a> tag with the right href attribute.

Want to add a YouTube or Vimeo video to your WordPress site? Most video platforms give you embed codes. These codes are usually HTML, often using <iframe> tags.

Just copy the embed code from YouTube (or wherever your video is hosted) and paste it into WordPress. WordPress knows what to do with it.

Need a bulleted list? Use <ul> tags. For a numbered list, use <ol> and <li> tags.

Want to add a line to separate sections of your content? The <hr> tag creates a horizontal rule. It’s a simple way to visually break up your text.

These are just a few examples, but you can see how HTML can be really useful in WordPress. It’s all about adding a little structure and extra functionality to your website content.

How to Learn WordPress HTML

So, you’re thinking, “Okay, HTML sounds useful, but how do I learn it?” Good question! Luckily, there are tons of great resources out there.

Here are a few places you can start learning HTML right now.

MDN Web Docs is like the encyclopedia of web development. It’s made by Mozilla (the folks behind Firefox) and it’s super comprehensive and reliable.

If you like interactive learning, Codecademy is awesome. They have courses where you actually write code right in your browser.

W3schools is a popular website for web development tutorials. They have tons of HTML examples and references.

Want to see how HTML is used specifically in WordPress? Check out the official WordPress developer documentation. It’s a bit more technical, but it’s a great resource as you get more comfortable.

No matter which resource you choose, the most important thing is practice. Seriously. You won’t learn HTML just by reading about it. You have to write code and see what happens.

Experiment! Don’t be afraid to break things. That’s how you learn.

How to Use WordPress HTML

There are a bunch of ways to use HTML in WordPress. Let’s go through them one by one.

1. Add a Custom HTML Block in the Block Editor

If you’re using the Block Editor (Gutenberg) in WordPress, you can use a special block just for HTML. It’s called the Custom HTML block.

To use it, just add a new block to your WordPress page or post. Search for “HTML” in the block search bar. You’ll see the Custom HTML block pop up.

Custom HTML WordPress block

Click on it to add it to your content. It’s just like adding any other block. You can even drag and drop it wherever you want it to go.

Once you add the block, you’ll see a box where you can type or paste your WordPress HTML code. Just put your HTML right in there.

WordPress block HTML

Click on Preview to see how your HTML code looks on the page without actually publishing it.

Preview HTML block

This is really handy for checking your code.

2. Edit a Block in HTML

Did you know you can edit any WordPress block as HTML? Yep, even those regular paragraph blocks.

This is useful if you want to make small HTML adjustments to a block that’s already there.

First, click on the block you want to edit. Then, look for the three dots in the block’s toolbar. Click on that.

A menu will pop up. In that menu, hit the Edit as HTML button.

Edit WordPress block as HTML

Suddenly, the block will transform! Instead of the usual visual editor, you’ll see the custom HTML code for that block. Now you can directly edit the HTML.

This is great for little tweaks. Maybe you want to add a specific class to a paragraph for styling later. Or maybe you need to fix a tiny formatting issue that’s easier to handle in HTML.

Once you’re done editing HTML, you can click Edit visually in the block toolbar to go back to the regular visual editor view.

3. Use the Code Editor in Gutenberg

For those who are comfortable with code, the WordPress block editor has a full-on Code Editor view. This shows you the HTML code for your entire post or page.

To switch to the Code Editor, look at the top right of your Gutenberg editor screen. You’ll see three dots there too – the main options menu for the whole editor. Click on those dots.

In that menu, you’ll see an option called Code editor. Click on it.

Open WordPress block code editor

You’ll see the tags and the structure of your whole page laid out in code.

This WordPress HTML editor is really for advanced users who prefer to work directly in code. If you like coding and want to see the big-picture HTML structure of your page, the Code Editor is for you.

But be careful! If you make mistakes in the HTML, you could mess up the layout of your page. It’s important to understand HTML if you’re going to use the Code Editor extensively.

If you want to go back to the regular visual editor, just go back to that top right menu and click Visual editor.

4. Add HTML with the Classic Editor

The Classic WordPress Editor has two tabs: Visual and Text. The Text tab is where you can get into the code.

Classic editor HTML

When you click Text, you’ll see all the HTML code for your post. This is where you can write or paste HTML code directly.

After you’ve added or edited your HTML, you can click back to the Visual tab to see how it looks. It will show you the rendered version of your HTML.

5. Use a WordPress Code Snippets Plugin

Sometimes you want to add little bits of HTML, CSS, or JavaScript to your WordPress site. Maybe you want to add some custom tracking code, or a special style for a certain part of your site.

You could edit your theme files to do this, but it can be risky. And if your theme updates, your changes might get overwritten.

That’s where code snippets plugins come in. These plugins let you add code snippets right through your WordPress dashboard.

They keep your code organized and separate from your theme files. This is much safer and easier to manage, especially if you’re not a code expert.

Before you add any code snippets, it’s always a good idea to back up your website! If something goes wrong with your code, you want to be able to easily restore your site.

Duplicator is a plugin that makes it super easy to create full backups of your WordPress site. I always recommend backing up before making code changes.

My favorite code snippets plugin is WPCode (formerly “Insert Headers and Footers”). This tool lets you add HTML, CSS, and JavaScript to your website.

WPCode plugin

Plus, there are tons of pre-made snippets for you to use if you’re not used to coding.

WP Code snippets

Using a code snippets plugin is way safer than directly editing theme files. It’s also easier to keep track of your custom code.

6. Add HTML in WordPress Widgets

WordPress comes with a built-in widget called for custom HTML. To find it, go to your WordPress dashboard and click on Appearance and then Widgets.

You’ll see different widget areas, like Sidebar or Footer. These depend on your WordPress theme.

Add the custom HTML widget into the widget area where you want to add your HTML.

WordPress widget HTML

Type or paste your HTML right into that box.

You can add all sorts of things with HTML in widgets. Custom text, images, links, even embed codes – it all works!

After you’ve added your HTML, click the Update button in the widget settings.

That’s it! Your HTML will now be live in that widget area on your website.

7. Edit HTML in WordPress Themes

You can actually go right into your WordPress theme files and edit the HTML there. This gives you a lot of control over your site’s structure, but it also comes with big risks.

Editing theme files directly can break your website if you’re not careful. One little mistake in the code can cause major problems.

If you’re going to edit theme files, I’d recommend always using a child theme. A child theme is like a safe copy of your main theme where you can safely make changes. This way, if your main theme updates, your changes won’t be overwritten.

Okay, warnings aside, here’s how you can edit theme files. In your WordPress dashboard, go to Appearance and then Theme File Editor (sometimes just called Theme Editor).

On the right side, you’ll see a list of your theme files. These files control the structure and layout of your website.

Theme file HTML

Some common files that contain HTML are:

  • header.php: This file usually controls the very top of your website – the header area.
  • footer.php: This file controls the very bottom – the footer area.
  • sidebar.php: If your theme has a sidebar, this file controls it.
  • index.php: This is often the main page of your website, showing your blog posts.
  • single.php: This controls how individual blog posts are displayed.
  • page.php: This controls how regular pages (like “About Us” or “Contact”) are displayed.
  • Template files: Your theme might have other template files for different types of pages.

You can edit the HTML directly in the Theme File Editor. Just click on a file to open it, find the HTML you want to change, and make your edits. Then click Update File to save your changes.

Remember: Only edit theme files if you really know what you’re doing, and always use a child theme and have a backup.

In my experience, I only edit theme files for very specific customizations that can’t be done in other ways. And even then, I’m super cautious. Child themes and Duplicator backups are always part of my workflow when I’m touching theme files.

8. Use FTP to Edit WordPress HTML

FTP stands for File Transfer Protocol. It gives you the most direct access to edit your WordPress theme files (and other files too).

To use FTP, you’ll need a few things:

  • An FTP Client: This is software that lets you connect to your server. Popular FTP clients are FileZilla, Cyberduck, and Transmit.
  • FTP Credentials: You’ll get these from your web hosting provider. They usually include your FTP host, username, password, and port number.

If you can’t find your FTP credentials, check your hosting account settings or contact support.

Once you have these, open your FTP client and enter your FTP credentials to connect to your server.

FileZilla Quickconnect

After you connect, you’ll see a view with two sides. One side shows files on your computer, and the other side shows files on your web server.

Navigate to your WordPress theme files on the server side. The path is usually something like /wp-content/themes/your-theme-name/.

WordPress themes in FTP

Once you’re backed up and you’re in your theme folder via FTP, you can download the theme HTML files to your computer or directly edit them.

Just right-click on the file in your FTP client and choose Download or View/Edit.

Edit theme files in FTP

Now, edit the downloaded file on your computer using a code editor. Good code editors for this are VS Code, Sublime Text, Atom, or Notepad++.

Open the file in your code editor and make your HTML changes.

Once you’re done adding HTML, save the file. Right-click on the file in your FTP client and choose Upload. This will overwrite the original file on your server with your edited version.

FTP is a powerful tool, but it requires some technical know-how. And it’s important to be responsible when using it. Always double-check your changes before uploading, and always have a backup ready.

Frequently Asked Questions (FAQs)

How do I add HTML code in Elementor?

Add HTML code in Elementor by using the HTML widget. Drag the widget into your layout, then paste your HTML code into the content box. This method allows you to insert custom HTML anywhere on your page without editing the theme files.

How do I add HTML code in WordPress headers?

Add HTML code in WordPress headers by inserting it into the <head> section using a plugin like WPCode. Install the plugin and find the Header & Footer tab. Add HTML code into the header code box and save your changes. This avoids editing theme files directly.

What’s the best WordPress code editor plugin?

The best WordPress code editor plugin is WPCode (formerly Insert Headers and Footers). WPCode lets you safely add custom code to your site without editing theme files. It supports adding CSS, HTML, JavaScript, and PHP. Plus, it includes error protection and conditional logic for targeted code placement.

Is WordPress HTML or PHP?

WordPress is built primarily with PHP, which runs on the server to generate dynamic content. It also uses HTML, CSS, and JavaScript to render and style web pages in the browser. PHP handles the backend logic, while HTML structures the content displayed to users.

Where can I find WordPress HTML templates?

Find WordPress HTML templates on marketplaces like ThemeForest or TemplateMonster. These platforms offer professionally designed HTML templates that can be adapted for WordPress development. Download, customize, and convert them using a page builder or theme framework.

Final Thoughts

Learning even a little bit of HTML can really open up a new world of possibilities with WordPress. It gives you more control, more flexibility, and a deeper understanding of how websites actually work.

Don’t be afraid to keep learning and experimenting. The more you play with code, the more comfortable you’ll become.

Explore those resources I mentioned, try out the different ways to add HTML in WordPress, and just see what you can create!

And remember, always back up your site before making big changes! Tools like Duplicator make backups a breeze, and they can save you a lot of headaches down the road.

While you’re here, I think you’ll like these other WordPress guides:

The post WordPress is Drag & Drop, BUT… Here’s Why I Still Mess with HTML appeared first on Duplicator.]]>