Using WordPress ‘customize_dynamic_partial_args’ PHP filter

The customize_dynamic_partial_args WordPress PHP filter is used to override the default constructor arguments for a dynamic partial in WP_Customize_Partial.

Usage

add_filter('customize_dynamic_partial_args', 'your_custom_function', 10, 2);
function your_custom_function($partial_args, $partial_id) {
  // your custom code here
  return $partial_args;
}

Parameters

  • $partial_args (false|array): The arguments to pass to the WP_Customize_Partial constructor.
  • $partial_id (string): The ID for the dynamic partial.

More information

See WordPress Developer Resources: customize_dynamic_partial_args

Examples

Change the container_inclusive argument for a dynamic partial

Change the container_inclusive argument for a specific dynamic partial ID.

add_filter('customize_dynamic_partial_args', 'change_container_inclusive', 10, 2);
function change_container_inclusive($partial_args, $partial_id) {
  if ('your_partial_id' === $partial_id) {
    $partial_args = array(
      'container_inclusive' => true,
    );
  }
  return $partial_args;
}

Set the settings property for a dynamic partial

Define the settings property for a specific dynamic partial ID.

add_filter('customize_dynamic_partial_args', 'set_settings_property', 10, 2);
function set_settings_property($partial_args, $partial_id) {
  if ('your_partial_id' === $partial_id) {
    $partial_args = array(
      'settings' => array('setting_1', 'setting_2'),
    );
  }
  return $partial_args;
}

Change the render_callback for a dynamic partial

Modify the render_callback for a specific dynamic partial ID.

add_filter('customize_dynamic_partial_args', 'change_render_callback', 10, 2);
function change_render_callback($partial_args, $partial_id) {
  if ('your_partial_id' === $partial_id) {
    $partial_args = array(
      'render_callback' => 'your_custom_render_callback',
    );
  }
  return $partial_args;
}

Set the selector for a dynamic partial

Define the selector for a specific dynamic partial ID.

add_filter('customize_dynamic_partial_args', 'set_selector', 10, 2);
function set_selector($partial_args, $partial_id) {
  if ('your_partial_id' === $partial_id) {
    $partial_args = array(
      'selector' => '.your_selector',
    );
  }
  return $partial_args;
}

Set multiple properties for a dynamic partial

Set multiple properties like selector, container_inclusive, and render_callback for a specific dynamic partial ID.

add_filter('customize_dynamic_partial_args', 'set_multiple_properties', 10, 2);
function set_multiple_properties($partial_args, $partial_id) {
  if ('your_partial_id' === $partial_id) {
    $partial_args = array(
      'selector' => '.your_selector',
      'container_inclusive' => true,
      'render_callback' => 'your_custom_render_callback',
    );
  }
  return $partial_args;
}