Adding Custom CSS in WordPress: Complete Guide

Custom CSS gives you control over your WordPress site’s style, letting you adjust everything from fonts and colors to layouts. Here’s a guide on how to add custom CSS to WordPress using different methods to fit your needs.

Method 1: Using WordPress’ Built-in Custom CSS Feature

WordPress has a built-in option for adding custom CSS right in the dashboard. It’s ideal for minor tweaks and beginner-friendly.

  1. Access the Customizer
    • Log in and go to Appearance > Customize.
  1. Select “Additional CSS”
    • In the left sidebar, click CSS adicional. A text box will appear where you can enter your CSS code.
  1. Add Your Custom CSS
    • Type in your code. For example:
  1. Pré-visualizar e publicar
    • You’ll see a live preview of changes. Once you’re happy, click Publicar.

Best For: Simple adjustments, no theme file edits needed.

Method 2: Using the Child Theme’s Style.css File

It’s better to use a child theme’s style.css file for more significant changes. This way, your edits stay safe even after theme updates.

  1. Enable a Child Theme
    • If you still need to start using one, create or install a child theme. Plugins like Child Theme Configurator make it easy.
  1. Access the Style.css File
    • In Appearance > Theme File Editor, select your child theme’s style.css ficheiro.
  1. Add Your CSS
    • Add your custom CSS at the bottom of the file. Example:
.custom-header { background-color: #2c3e50; color: #ffffff; }
.custom-button { background-color: #e74c3c; color: #ffffff; padding: 10px 20px; border-radius: 5px; }
  1. Guardar alterações
    • Clique em Update File to save.

Best For: Bigger style changes that should stick around after updates.

Method 3: Adding Custom CSS with a Plugin

If you’d rather avoid editing files or child themes, plugins can handle custom CSS. This is great for managing CSS across multiple pages.

Example Using WPCode:

  1. Install WPCode
    • Aceda a Plugins > Adicionar novo Plugin, search for Código WPC, install, and activate.
  1. Crie um New CSS Snippet
    • Head to Code Snippets > Add Snippet. Choose CSS Snippet.
  1. Escolha a colocação
    • For CSS to work site-wide, select Site-Wide Header.

Best For: Easy CSS management without touching theme files.

Method 4: Adding Custom CSS via Page Builders (Elementor, Divi)

Page builders like Elementor and Divi usually have CSS options built-in, making it simple to manage styles.

In Elementor:

  1. Select Element and Access Avançado Definições
    • In Elementor, select an element, go to Avançado settings, and find CSS personalizado (Elementor Pro).
  1. Enter CSS Code
    • Use the selector keyword to target the element. Example:
selector { background-color: #333; color: #fff; }

In Divi:

  1. Go to Theme Options
    • Navegue até Divi > Theme Options > Custom CSS.
  1. Enter and Save CSS Code
    • Add your custom CSS and save.

Best For Those already using page builders with easy access to custom CSS.

Method 5: Directly Adding CSS via FTP or Code Editor

If you’re familiar with FTP and want complete control, you can edit CSS files directly on the server.

Passos:

  1. Connect via FTP
    • Use an FTP client (like FileZilla) to connect to your site.
  2. Navigate to the Theme Folder
    • Go to wp-content/themes/your-child-theme/ and open style.css.
  1. Edit and Upload
    • Add your custom CSS, save, and upload.

Best For: Advanced users needing complete control.

Perguntas mais frequentes

1. Why isn’t my custom CSS working?

Clear your browser cache or any site caching plugins, as caching might be blocking updates.

2. How do I prevent CSS from being lost during updates?

Use a child theme or plugin to store CSS rather than modifying the parent theme’s files.

Related Articles

Responses

O seu endereço de email não será publicado. Campos obrigatórios marcados com *