Using WordPress ‘customize_partial_render_{$partial->id}’ PHP filter

The customize_partial_render_{$partial->id} WordPress PHP filter allows you to modify the partial rendering for a specific partial in the WordPress Customizer. The dynamic portion of the filter name, $partial->ID, refers to the partial ID.

Usage

add_filter( 'customize_partial_render_' . $partial_id, 'my_custom_function', 10, 3 );

function my_custom_function( $rendered, $partial, $container_context ) {
    // your custom code here
    return $rendered;
}

Parameters

  • $rendered (string|array|false): The partial value. Default false.
  • $partial (WP_Customize_Partial): WP_Customize_Setting instance.
  • $container_context (array): Array of context data associated with the target container.

More information

See WordPress Developer Resources: customize_partial_render_{$partial->id}

Examples

Change the site title rendering

In this example, we’ll modify the rendering of the site title by adding a custom prefix.

add_filter( 'customize_partial_render_blogname', 'change_site_title', 10, 3 );

function change_site_title( $rendered, $partial, $container_context ) {
    $custom_prefix = 'Custom Prefix: ';
    return $custom_prefix . $rendered;
}

Append a custom text to the site tagline

In this example, we’ll append custom text to the site tagline.

add_filter( 'customize_partial_render_blogdescription', 'append_tagline_text', 10, 3 );

function append_tagline_text( $rendered, $partial, $container_context ) {
    $custom_text = ' - Your trusted source!';
    return $rendered . $custom_text;
}

In this example, we’ll change the copyright text in the footer.

add_filter( 'customize_partial_render_copyright_text', 'change_copyright_text', 10, 3 );

function change_copyright_text( $rendered, $partial, $container_context ) {
return ‘© ‘ . date( ‘Y’ ) . ‘ My Custom Copyright Text’;
}

In this example, we’ll display a custom message when there is no featured image available.

add_filter( 'customize_partial_render_featured_image', 'custom_featured_image_message', 10, 3 );

function custom_featured_image_message( $rendered, $partial, $container_context ) {
    if ( !$rendered ) {
        return 'No featured image available';
    }
    return $rendered;
}

Modify the rendering of a custom partial

In this example, we’ll modify the rendering of a custom partial with the ID my_custom_partial.

add_filter( 'customize_partial_render_my_custom_partial', 'modify_custom_partial', 10, 3 );

function modify_custom_partial( $rendered, $partial, $container_context ) {
    // Modify the $rendered content as needed
    return $rendered;
}