Custom Ad Types

Get Started

WB Ad Manager ships with several built-in ad types (image, HTML, rich content, AdSense, etc.), but you can register your own custom ad types to support any format your site needs. Custom ad types integrate seamlessly with the plugin’s rotation engine, targeting system, and analytics tracking.

This guide walks you through implementing the Ad_Type_Interface, rendering admin fields and frontend output, and registering your custom type with the plugin.


Creating a Custom Ad Type

To create a custom ad type, implement the Ad_Type_Interface. The interface requires methods for identification, admin form rendering, data sanitization, and frontend output:

use WBAM\Modules\AdTypes\Ad_Type_Interface;

class Video_Ad implements Ad_Type_Interface {

    /**
     * Get ad type ID.
     */
    public function get_id() {
        return 'video';
    }

    /**
     * Get ad type label.
     */
    public function get_label() {
        return __( 'Video Ad', 'my-plugin' );
    }

    /**
     * Get ad type description.
     */
    public function get_description() {
        return __( 'Display video advertisements.', 'my-plugin' );
    }

    /**
     * Get ad type icon.
     */
    public function get_icon() {
        return 'dashicons-video-alt3';
    }

    /**
     * Render the admin form fields.
     */
    public function render_fields( $ad_id ) {
        $data = get_post_meta( $ad_id, '_wbam_ad_data', true );
        $video_url = isset( $data['video_url'] ) ? $data['video_url'] : '';
        ?>
        <p>
            <label for="wbam_video_url"><?php esc_html_e( 'Video URL', 'my-plugin' ); ?></label>
            <input type="url" id="wbam_video_url" name="wbam_ad_data[video_url]"
                   value="<?php echo esc_url( $video_url ); ?>" class="widefat">
        </p>
        <?php
    }

    /**
     * Sanitize ad data before saving.
     */
    public function sanitize( $data ) {
        if ( isset( $data['video_url'] ) ) {
            $data['video_url'] = esc_url_raw( $data['video_url'] );
        }
        return $data;
    }

    /**
     * Render the ad output.
     */
    public function render( $ad_id, $options = array() ) {
        $data = get_post_meta( $ad_id, '_wbam_ad_data', true );
        $video_url = isset( $data['video_url'] ) ? $data['video_url'] : '';

        if ( empty( $video_url ) ) {
            return '';
        }

        ob_start();
        ?>
        <div class="wbam-ad wbam-video-ad" data-ad-id="<?php echo esc_attr( $ad_id ); ?>">
            <video src="<?php echo esc_url( $video_url ); ?>" controls></video>
        </div>
        <?php
        return ob_get_clean();
    }
}

Interface Methods

Method Return Type Description
get_id() string Unique identifier for the ad type (e.g., 'video', 'carousel').
get_label() string Human-readable label shown in the admin UI.
get_description() string Short description of what the ad type does.
get_icon() string Dashicons class name for the admin UI icon.
render_fields( $ad_id ) void Outputs the HTML form fields in the ad editor metabox.
sanitize( $data ) array Sanitizes and returns the ad data array before saving to the database.
render( $ad_id, $options ) string Returns the frontend HTML output for the ad.

Registering the Ad Type

Use the wbam_register_ad_types action to register your custom ad type with the placement engine:

add_action( 'wbam_register_ad_types', function( $engine ) {
    $engine->register_ad_type( new Video_Ad() );
} );

Once registered, your custom ad type will appear in the ad type selector when creating or editing ads, and it will work with all existing placements, targeting rules, and analytics tracking automatically.

Last updated: March 4, 2026