Skip to content

Hooks—Header and Footer

Jo Dickson edited this page Oct 27, 2021 · 1 revision

Navigation

Actions

Filters


after_body_open

Deprecated in v0.7.3-- Use wp_body_open instead.

This action executes in header.php, immediately below where the university header renders, and immediately above the site header/navigation. Use it to echo markup or scripts that have to be placed after the document's opening <body> tag.

Parameters

n/a

Example usage

// Echo text immediately above the site header (below the university header)
function pre_header_content() {
    echo '...';
}

add_action( 'after_body_open', 'pre_header_content' );

ucfwp_get_header_images_before

Allows for early overriding of the per-breakpoint header images that are fetched for a given post or term object.

Parameters

  • $images array

    An associative array of image size strings and the attachment IDs for those sizes, before custom meta values are retrieved. Expected format:

    array(
        'header_image' => '',
        'header_image_xs' => ''
    )
  • $obj object

    The current WP_Post or WP_Term object

Return

array: An associative array of image size strings and the attachment IDs for those sizes

Example usage

// Enforce a consistent set of header images for all 'person' posts,
// regardless of page meta field values available/set.
function person_header_images( $images, $obj ) {
    if ( $obj instanceof WP_Post && $obj->post_type === 'person' ) {
        $person_header_img = 1234; // Replace value with an actual attachment ID, e.g. fetched from a Customizer option
        $person_header_img_xs = 5678; // Replace value with an actual attachment ID, e.g. fetched from a Customizer option

        $images['header_image'] = $person_header_img;
        $images['header_image_xs'] = $person_header_image_xs;
    }

    return $images;
}

add_filter( 'ucfwp_get_header_images_before', 'person_header_images', 10, 2 );

ucfwp_get_header_images_after

Allows for late overriding of the per-breakpoint header images that are fetched for a given post or term object.

Parameters

  • $images array

    An associative array of image size strings and the attachment IDs for those sizes. Expected format:

    array(
        'header_image' => '',
        'header_image_xs' => ''
    )
  • $obj object

    The current WP_Post or WP_Term object

Return

array: An associative array of image size strings and the attachment IDs for those sizes

Example usage

// Apply a set of fallback header images if the post/term
// doesn't already have its own header_image size defined
function fallback_header_images( $images, $obj ) {
    // 'header_image' size is required for any header image to be displayed
    if ( ! isset( $images['header_image'] ) || empty( $images['header_image'] ) ) {
        $fallback_header_img = 1234; // Replace value with an actual attachment ID, e.g. fetched from a Customizer option
        $fallback_header_img_xs = 5678; // Replace value with an actual attachment ID, e.g. fetched from a Customizer option

        $images['header_image'] = $fallback_header_img;
        $images['header_image_xs'] = $fallback_header_image_xs;
    }

    return $images;
}

add_filter( 'ucfwp_get_header_images_after', 'fallback_header_images', 10, 2 );

ucfwp_get_header_videos_before

Allows for early overriding of the header videos that are fetched for a given post or term object.

Parameters

  • $videos array

    An associative array of video type strings and the attachment urls for those sizes, before custom meta values are retrieved. Expected format:

    array(
        'webm' => '',
        'mp4' => ''
    )
  • $obj object

    The current WP_Post or WP_Term object

Return

array: An associative array of video type strings and the urls for those types


ucfwp_get_header_videos_after

Called in ucfwp_get_header_videos(). Allows for late overriding of the header videos that are fetched for a given post or term object.

Parameters

  • $videos array

    An associative array of video type strings and the attachment urls for those sizes. Expected format:

    array(
        'webm' => '',
        'mp4' => ''
    )
  • $obj object

    The current WP_Post or WP_Term object

Return

array: An associative array of video type strings and the urls for those types


ucfwp_get_header_title_before

Allows for early overriding of the title (h1) text used for the given post/term object.

Parameters

  • $title string

    The post/term title, before theme-specific title logic and custom page header values are applied

  • $obj object

    The current WP_Post or WP_Term object

Return

string: The title text to use for the post/term object


ucfwp_get_header_title_after

Allows for late overriding of the title (h1) text used for the given post/term object, after theme logic and custom meta values are applied.

Parameters

  • $title string

    The post/term title, after theme-specific title logic and custom page header values are applied

  • $obj object

    The current WP_Post or WP_Term object

Return

string: The title text to use for the post/term object


ucfwp_get_header_subtitle_before

Allows for early overriding of the subtitle text used for the given post/term object.

Parameters

  • $subtitle string

    The post/term subtitle, before custom page header values are applied

  • $obj object

    The current WP_Post or WP_Term object

Return

string: The subtitle text to use for the post/term object


ucfwp_get_header_subtitle_after

Allows for late overriding of the subtitle text used for the given post/term object, after custom meta values are applied.

Parameters

  • $subtitle string

    The post/term subtitle, after custom page header values are applied

  • $obj object

    The current WP_Post or WP_Term object

Return

string: The subtitle text to use for the post/term object

Clone this wiki locally