Home » Blog » How to Add Custom Attributes to WordPress Blocks (Without Code)

How to Add Custom Attributes to WordPress Blocks (Without Code)

·

Are you building a site with a block theme? Cool, it feels modern, visual, and empowering. You can drag, drop, and design entire layouts without touching code.

Then comes that moment when you want a little more control. Maybe you need to target one section with CSS, add a scroll animation, or include some data-attributes. Suddenly, you realize the editor does not give you any direct way to do that.

And of course, a question pops into your mind:

Why does the default block editor limit customization?

WordPress avoids exposing advanced controls to keep beginners from accidentally breaking their layouts. This design philosophy is explained in the official documentation on the block editor’s goals, which emphasize simplicity and usability for a broad audience. Manually editing HTML or template files just to add an ID or class defeats the whole purpose of visual editing.

That is where the Attributes for Blocks plugin comes in. It is a simple, lightweight, and clever solution that gives you full control right inside the editor.

What the Attributes for Blocks Plugin Does?

So here’s where things start to get fun. The Attributes for Blocks plugin quietly adds a new little section in your block settings called Additional Attributes. That’s where the magic happens.

how to add custom attributes to WordPress blocks without code
how to add custom attributes to WordPress blocks without code

From there, you can drop in whatever you need:

  • Add your own custom ID for smooth scrolling or anchor navigation.
  • Add custom classes to style sections or trigger animations.
  • Add data attributes like data-aos, data-delay, or anything your JavaScript needs.

Everything happens right inside the editor. You don’t need to jump into templates or edit HTML. It’s quick, clean, and gives you that extra bit of control that every block theme builder secretly wants.

Step-by-Step: How to Use Attributes for Blocks

  • Install and activate the plugin
    1. Go to Dashboard → Plugins → Add New.
    2. Search for “Attributes for Blocks.”
    3. Click Install Now and then Activate.
  • Edit any page or post
    • Select a block such as a heading, paragraph, or group.
    • In the right sidebar, find the AdvancedAdditional Attributes panel.
  • Add your attributes
    • ID: about-section or hero-banner
    • Classes: fade-in, highlight, custom-box
    • Data Attributes: data-aos="fade-up" or data-delay="300"
  • Save and preview your page
    • Your output might look like this:
<section class="wp-block-group fade-in" id="about-section" data-aos="fade-up">
<h2>About Our Services</h2>
</section>

Everything happens visually inside the block editor, no need to open the code view.

Real-World Use Cases for Block Themes

1. Smooth Scrolling Navigation

Give each section its own unique ID. Then just link your buttons or menu items to those IDs for clean, smooth scrolling between sections.

Example:

<a href="#contact-section">Contact Us</a>

It’s that simple. No plugins, no clutter. Just add your ID in the Attributes panel, and your navigation works like a charm.

2. Scroll-Based Animations

If you’re using something like AOS or a custom animation library, this plugin becomes your best friend. Add your data-aos attributes right inside the editor.
Each section fades, slides, or pops into view as you scroll — no need to hard-code anything or load heavy scripts.

3. JavaScript Hooks and Triggers

Need a quick trigger for a modal or a custom script? Easy.
Add something like:

data-trigger="modal"

and in your JS file:

document.querySelectorAll('[data-trigger="modal"]').forEach(btn => {
btn.addEventListener('click', openModal);
});

It keeps your logic neat, readable, and easy to maintain when your project grows.

Pros

  • Works with all core and third-party blocks.
  • Lightweight and fits perfectly with any block theme.
  • Great for styling, animations, and JavaScript hooks.
  • You don’t have to touch a single line of template code.

Cons

  • You’ll need a basic idea of how IDs and classes work.
  • If you add too many attributes everywhere, your HTML can get messy.

Final Thoughts

Attributes for Blocks is one of those plugins you install once and wonder how you ever worked without it. It gives you real control while keeping your block theme clean and flexible.

If you build sites for clients or manage your own projects, this plugin helps you keep everything consistent, organized, and professional.

👉 Read my full guide on 7 Essential WordPress Block Plugins to explore more tools that make building block themes faster, smarter, and way more fun.

Get a Free Website Performance Audit

Find out how fast, secure, and optimized your WordPress website really is.

I’ll analyze your site’s loading speed, server performance, and overall technical health — and send you a short report with practical improvements you can apply right away.

Just share your website URL below, and I’ll handle the rest.

Select list(s):

*We hate spam too, and will never share your email address or send any crap! Unsubscribe anytime.

👋 Hi! I’m Muzammil – yes, the one who builds.

I’m a creative full-stack engineer obsessed with crafting experiences that feel as good as they function.
Currently, I’m helping businesses grow through design-driven development and clean, scalable code.

One response to “How to Add Custom Attributes to WordPress Blocks (Without Code)”

  1. 7 WordPress Block Plugins to Build Better Block Themes | Muzammil

    […] If you want a complete walkthrough with real examples, check out my full article: How to Add Custom Attributes to WordPress Blocks (Without Code). […]

Leave a Reply