What is Repeater control in Elementor? How to properly add Repeater Control to Elementor

What is Repeater control in Elementor? How to properly add Repeater Control to Elementor

Share

In the WordPress ecosystem, Elementor has shifted from being a simple page builder to a full-blown development framework. But as you move from “user” to “creator,” you eventually hit a ceiling with standard widgets. You realize that static fields—one text box for one headline—simply aren’t enough for modern web design.

If you’ve ever wanted to build a Custom Testimonial Slider, an Accordion with unlimited rows, or a Dynamic Pricing Table, you need to master the Repeater Control.

In this comprehensive guide, we’ll explore everything from the basic syntax to advanced performance optimization for the Elementor Repeater.

What Exactly is the Elementor Repeater Control?

In technical terms, the Repeater is a UI wrapper for an array of data. In layman’s terms, it’s a “List Maker” for your widget’s sidebar.

Standard controls are 1:1. You add a TEXT control, and the user gets one text box. The Repeater control is 1:N (One-to-Many). You define a “template” of controls, and the user can press a button to duplicate that template as many times as they wish.

Real-World Use Cases:

  • Icon Lists: A set of features where each item needs an icon, a title, and a link.

  • Team Members: A gallery where each entry requires a photo, name, job title, and social media links.

  • Timelines: A vertical list where each point has a date, description, and color setting.

 

Why Developers Love (and Need) Repeaters

If you were coding a site from scratch, you might use a Repeater field in ACF (Advanced Custom Fields). The Elementor Repeater is the native equivalent for widget development.

Clean Code vs. Messy Code

Without a repeater, if you wanted to allow up to 5 features, you would have to register 15 separate controls (Feature 1 Title, Feature 1 Icon, Feature 1 Link… up to Feature 5).

With a repeater, you register one control. This makes your PHP file significantly smaller and much easier to maintain. If you decide to add a “Color” option to the features later, you add it once to the repeater template, and it instantly becomes available for all items.

The User Experience (UX) Factor

For the end-user (the person building the page), a repeater feels intuitive. It allows them to drag-and-drop items to reorder them, delete specific rows, or duplicate an existing row to save time.

The Technical Architecture: How it Works Under the Hood

Before writing code, it helps to understand how Elementor handles this data.

  1. The PHP Side: When the user saves the page, Elementor stores the Repeater data as a multidimensional array in the WordPress database (within the post meta).

  2. The JS Side: In the editor, Elementor uses Backbone.js and Underscore.js. The repeater is managed as a “Collection.” When a user adds an item, the JS model updates, and the “Live Preview” re-renders.

Step-by-Step Implementation: Coding the Repeater

Let’s build a “Brand Logo Grid” widget. Each item in our repeater will have an image (the logo), a text field (the company name), and a URL (the company website).

Step 1: Initialize the Repeater Class

Inside your widget’s register_controls() method, you must first create a new instance of the Repeater class. This acts as a temporary container for your sub-controls.

$repeater = new \Elementor\Repeater();

Step 2: Define the “Sub-Controls”

Now we add the fields to the $repeater object. Note that these IDs (company_name, company_logo) only need to be unique within the repeater.

$repeater->add_control(
‘company_name’, [
‘label’ => esc_html__( ‘Company Name’, ‘text-domain’ ),
‘type’ => \Elementor\Controls_Manager::TEXT,
‘default’ => esc_html__( ‘Google’ , ‘text-domain’ ),
‘label_block’ => true,
]
);
$repeater->add_control(
‘company_logo’, [
‘label’ => esc_html__( ‘Choose Logo’, ‘text-domain’ ),
‘type’ => \Elementor\Controls_Manager::MEDIA,
‘default’ => [
‘url’ => \Elementor\Utils::get_placeholder_image_src(),
],
]
);
$repeater->add_control(
‘company_website’, [
‘label’ => esc_html__( ‘Website Link’, ‘text-domain’ ),
‘type’ => \Elementor\Controls_Manager::URL,
‘placeholder’ => esc_html__( ‘https://your-link.com’, ‘text-domain’ ),
]
);

Step 3: Register the Main Repeater Control

Now, we attach that $repeater object to our widget’s main control section.

$this->add_control(
‘brands_list’,
[
‘label’ => esc_html__( ‘Brand Logos’, ‘text-domain’ ),
‘type’ => \Elementor\Controls_Manager::REPEATER,
‘fields’ => $repeater->get_controls(), // This pulls in the fields we defined above
‘default’ => [
[
‘company_name’ => esc_html__( ‘Company #1’, ‘text-domain’ ),
],
],
‘title_field’ => ‘{{{ company_name }}}’,
]
);
The title_field Secret: Using {{{ company_name }}} allows the Elementor sidebar to show the actual name of the company on the collapsed list item. This is vital for usability when a user has 20 items.

Frontend Rendering: Displaying the Data

Now that the data is saved, we need to show it. This happens in the render() method. We will use a foreach loop to iterate through the array.

protected function render() {
$settings = $this->get_settings_for_display();
if ( ! empty( $settings[‘brands_list’] ) ) {
echo ‘<div class=”brand-grid”>’;
foreach ( $settings[‘brands_list’] as $item ) {
// Get the URL data
$url = $item[‘company_website’][‘url’];
echo ‘<div class=”brand-item”>’;
if ( $url ) { echo ‘<a href=”‘ . esc_url( $url ) . ‘”>’; }
// Render the image
echo ‘<img src=”‘ . esc_url( $item[‘company_logo’][‘url’] ) . ‘” alt=”‘ . esc_attr( $item[‘company_name’] ) . ‘”>’;
if ( $url ) { echo ‘</a>’; }
echo ‘<h4>’ . $item[‘company_name’] . ‘</h4>’;
echo ‘</div>’;
}
echo ‘</div>’;
}
}

Achieving “Instant” Previews with _content_template

If you stop at the PHP render() method, the user will have to wait for the page to refresh every time they add a new item or change a title. To make it feel like a modern app, you need to use the _content_template() method.

This uses Underscore.js syntax. It’s essentially a JavaScript version of your PHP loop.

protected function _content_template() {
?>
<# if ( settings.brands_list.length ) { #>
<div class=”brand-grid”>
<# _.each( settings.brands_list, function( item ) { #>
<div class=”brand-item”>
<img src=”{{ item.company_logo.url }}” />
<h4>{{{ item.company_name }}}</h4>
</div>
<# } ); #>
</div>
<# } #>
<?php
}

SEO and Performance Considerations

When building widgets with Repeaters, it’s easy to accidentally create “Heavy” pages. Here is how to keep your site fast and SEO-friendly:

Image Optimization

Inside a repeater, users often upload massive images. Use Elementor’s Group_Control_Image_Size inside your repeater to allow users to choose thumbnail sizes (e.g., thumbnail, medium, large). This prevents loading a 4K image for a tiny logo grid.

DOM Depth

Every item in a repeater adds HTML tags. If you have a repeater inside a repeater (yes, it’s possible!), you can quickly end up with a “Deep DOM” warning in Google PageSpeed Insights. Keep your HTML wrapper structure as flat as possible.

Semantic HTML

Ensure your repeater items use proper tags. If the repeater is a list of services, use <ul> and <li>. If it’s a set of articles, use <article>. Search engines use this structure to understand the relationship between the items in your list.

Common Errors and How to Fix Them

“Class ‘Elementor\Repeater’ not found”

This usually happens because of a Namespace issue. If you are coding inside a specific namespace, you must use the absolute path: $repeater = new \Elementor\Repeater(); (with the leading backslash).

“The Title Field is showing ‘Item #1′”

Check your title_field setting. It must match the ID of one of the controls inside the repeater and must be wrapped in triple curly braces: {{{ control_id }}}.

“Changes aren’t showing in the Live Preview”

This means there is a mismatch between your render() (PHP) and your _content_template() (JS). Ensure that the logic in both is identical. If you added a new field to PHP, you must add it to the JS template as well.

Expanding Your Knowledge: Nested Repeaters

Did you know you can put a Repeater inside a Repeater? Example: A “Menu” widget where the top-level repeater is the “Category” (Appetizers, Mains, Drinks) and the inner repeater is the “Individual Dish.”

While powerful, use nested repeaters sparingly. They can make the Elementor editing panel feel sluggish and complex for the end-user.

Summary and Key Takeaways

The Elementor Repeater control is the bridge between static web design and dynamic application building. By following the Initialize -> Define -> Register -> Render workflow, you can build any complex layout imaginable.

Key Points to Remember:

  1. Always use _content_template for the best user experience.

  2. Use title_field to keep the editor organized.

  3. Sanitize your output using esc_url and esc_html in your PHP render.

  4. Leverage Default Values so the widget looks good the moment it’s dragged onto the page.

 

Next Steps for Your Development Journey

Now that you understand the theory and the code, the best way to learn is by doing.

Control Elementor Repeater

Related Blogs

Scroll to Top