Add Widget Title Prefix and Suffix

Add a prefix and suffix to widget titles.

<?php
function widget_title_prefix_suffix($title, $instance, $widget) {
    $prefix = '<span class="widget-title-prefix">[</span>';
    $suffix = '<span class="widget-title-suffix">]</span>';
    
    if (isset($instance['prefix'])) {
        $prefix = $instance['prefix'];
    }
    if (isset($instance['suffix'])) {
        $suffix = $instance['suffix'];
    }

    return $prefix . $title . $suffix;
}
add_filter('widget_title', 'widget_title_prefix_suffix', 10, 3);

Post Comment