Description

This action can be used to output data for all Conductor Widgets. It can also be used to add or remove output data for specific Conductor Widgets (see example below). By default, upon instantiation, the Conductor_Widget_Query class hooks into conductor_widget_display_content_{$widget_number} to display data. The conductor_widget_display_content action is executed before the individual/specific (widget number) Conductor Widget display content hook.

Note: To output data for individual/specific Conductor Widgets see the conductor_widget_display_content_{$widget_number} documentation page.

This action is executed when the Conductor_Widget::widget() function is called (when a Conductor Widget is displayed, after the query is initialized).

Technical Details

  • Type: Action
  • Parameters:
    • $post (WP_Post): The WP_Post object for the current post
    • $instance (array): The Conductor Widget instance (settings)
    • $widget(Conductor_Widget): The Conductor Widget instance
    • $conductor_widget_query (Conductor_Widget_query): The Conductor Widget Query instance

Resources

Examples

The following example removes the featured image output element from the conductor_widget_display_content_{$widget_number} hook based on the current post ID.

<?php
/**
* This function removes the featured image output element from the conductor_widget_display_content_{$widget_number} hook on the
* current post ID.
*/
add_action( 'conductor_widget_display_content', 'my_conductor_widget_display_content', 10, 4 );
function my_conductor_widget_display_content( $post, $instance, $widget, $conductor_widget_query ) {
// List of post IDs to remove the featured image output element from
$post_ids_to_remove_featured_image = array( 1, 2, 39, 683 );
// Grab the featured image output element data
$featured_image_output_el_priority = $instance['output_elements']['featured_image'];
$featured_image_output_el = $instance['output'][$featured_image_output_el_priority];
// If this post ID matches a post ID specified in our array, remove the featured image output element
if ( in_array( $post->ID, $post_ids_to_remove_featured_image ) ) {
// If the featured image output element callback function exists from the Conductor_Widget_Query class
if ( has_action( 'conductor_widget_display_content_' . $widget->number, array( $conductor_widget_query, $featured_image_output_el['callback'] ) ) )
// Remove the featured image output element from display
remove_action( 'conductor_widget_display_content_' . $widget->number, array( $conductor_widget_query, $featured_image_output_el['callback'] ), $featured_image_output_el_priority );
}
// Otherwise, let's make sure the featured image output element is added at the correct priority
else {
// If the featured image output element callback function doesn't exist from the Conductor_Widget_Query class
if ( ! has_action( 'conductor_widget_display_content_' . $widget->number, array( $conductor_widget_query, $featured_image_output_el['callback'] ) ) )
// Re-add the featured image output element to display
add_action( 'conductor_widget_display_content_' . $widget->number, array( $conductor_widget_query, $featured_image_output_el['callback'] ), $featured_image_output_el_priority, $conductor_widget_query->display_content_args_count );
}
}

The following example outputs data before all Conductor Widgets.

<?php
/**
* This function adds a callback function to output custom data on all Conductor Widgets.
*/
add_action( 'conductor_widget_display_content', 'my_conductor_widget_display_content', 10, 4 );
function my_conductor_widget_display_content( $post, $instance, $widget, $conductor_widget_query ) {
// Hook into 'conductor_widget_display_content_{$widget->number} before the Conductor Widget output elements
add_action( 'conductor_widget_display_content_' . $widget->number, 'conductor_widget_display_content_custom', 5, $conductor_widget_query->display_content_args_count );
}
/**
* This function outputs custom data on all Conductor Widgets.
*/
function conductor_widget_display_content_custom( $post, $instance, $widget, $conductor_widget_query ) {
?>
<span class="my-custom-data"><?php _e( 'My Custom Data', 'text-domain' ); ?></span>
<?php
}