Code Examples Overview#
These recipes demonstrate recommended patterns for extending Jalpi Page Builder in child themes or custom companion plugins. All code strictly adheres to Jalpi's decoupled React/PHP architecture and security standards.
Recipe 1: Call to Action Banner#
A lightweight, responsive Call to Action widget declaring heading, description, button text, link URL, and background color controls:
class Jalpi_Element_CTA_Banner extends Jalpi_Element_Base {
public function get_name(): string { return 'cta-banner'; }
public function get_title(): string { return __( 'CTA Banner', 'theme' ); }
public function get_icon(): string { return 'announcement'; }
public function get_categories(): array { return [ 'interactive' ]; }
protected function register_controls(): void {
$this->start_controls_section( 'content_sec', [ 'label' => 'Banner Content' ] );
$this->add_control( 'headline', [ 'type' => 'text', 'label' => 'Headline', 'default' => 'Special Offer' ] );
$this->add_control( 'subline', [ 'type' => 'textarea', 'label' => 'Subline' ] );
$this->add_control( 'btn_label', [ 'type' => 'text', 'label' => 'Button Text', 'default' => 'Claim Deal' ] );
$this->add_control( 'btn_url', [ 'type' => 'url', 'label' => 'Button Link' ] );
$this->end_controls_section();
}
protected function render( array $settings, array $node ): void {
$headline = esc_html( $settings['headline'] ?? '' );
$subline = esc_html( $settings['subline'] ?? '' );
$btn_text = esc_html( $settings['btn_label'] ?? '' );
$btn_url = esc_url( $settings['btn_url']['url'] ?? '#' );
echo '<div class="jalpi-cta-banner">';
if ( $headline ) echo '<h3 class="cta-headline">' . $headline . '</h3>';
if ( $subline ) echo '<p class="cta-subline">' . $subline . '</p>';
if ( $btn_text ) echo '<a href="' . $btn_url . '" class="cta-btn">' . $btn_text . '</a>';
echo '</div>';
}
}Recipe 2: Testimonial Card#
An elegant testimonial card with avatar image upload, author name, position/company, and quote content:
class Jalpi_Element_Testimonial_Card extends Jalpi_Element_Base {
public function get_name(): string { return 'testimonial-card'; }
public function get_title(): string { return __( 'Testimonial Card', 'theme' ); }
public function get_icon(): string { return 'format-quote'; }
public function get_categories(): array { return [ 'basic' ]; }
protected function register_controls(): void {
$this->start_controls_section( 'testimonial_sec', [ 'label' => 'Testimonial' ] );
$this->add_control( 'quote', [ 'type' => 'textarea', 'label' => 'Quote' ] );
$this->add_control( 'author', [ 'type' => 'text', 'label' => 'Author Name' ] );
$this->add_control( 'company', [ 'type' => 'text', 'label' => 'Company / Role' ] );
$this->add_control( 'avatar', [ 'type' => 'media', 'label' => 'Author Avatar' ] );
$this->end_controls_section();
}
protected function render( array $settings, array $node ): void {
$quote = esc_html( $settings['quote'] ?? '' );
$author = esc_html( $settings['author'] ?? '' );
$company = esc_html( $settings['company'] ?? '' );
$avatar = esc_url( $settings['avatar']['url'] ?? '' );
echo '<blockquote class="jalpi-testimonial-card">';
if ( $avatar ) echo '<img src="' . $avatar . '" alt="' . $author . '" class="testimonial-avatar" />';
echo '<p class="testimonial-quote">“' . $quote . '”</p>';
echo '<cite class="testimonial-author"><strong>' . $author . '</strong><span>' . $company . '</span></cite>';
echo '</blockquote>';
}
}Recipe 3: Dynamic Post Query Widget#
Query WordPress posts safely on the public frontend using standard WP_Query loops with post count limits:
protected function render( array $settings, array $node ): void {
$count = absint( $settings['posts_per_page'] ?? 3 );
$query = new WP_Query( [
'post_type' => 'post',
'posts_per_page' => $count,
'post_status' => 'publish'
] );
if ( $query->have_posts() ) {
echo '<div class="jalpi-post-cards">';
while ( $query->have_posts() ) {
$query->the_post();
echo '<article class="card">';
echo '<h4><a href="' . esc_url( get_permalink() ) . '">' . esc_html( get_the_title() ) . '</a></h4>';
echo '<p>' . esc_html( wp_trim_words( get_the_excerpt(), 18 ) ) . '</p>';
echo '</article>';
}
echo '</div>';
wp_reset_postdata();
}
}Recipe 4: Custom Category Registration#
Add a dedicated branded category to group your agency's custom widgets at the top of the editor drawer:
add_filter( 'jalpi_widget_categories', function( $categories ) {
$categories['agency'] = [
'title' => __( 'Agency Components', 'my-agency' ),
'icon' => 'star-filled',
'order' => 1
];
return $categories;
} );Related Documentation#
Related Resources
- Your First Widget β Step-by-step element building guide.
- Managing Widgets β Complete lifecycle and registration overview.
- Hooks & Extension Points β Filter and action matrix.
Last updated: November 2026