Alter the Page Header Background Image

This is a Developer Level doc.

If you're unfamiliar with PHP and/or editing files, codes and templates, as well as with resolving possible conflict, please seek help from a professional. Under our Support Policy, we don't provide support for modifications and customization.

/**
 * Add the background image style for the "post" post type
 */
function my_page_header_style( $style ) {

	if ( is_singular( 'post' ) ) {
		$style = 'background-image';
	}

	// Retrun
	return $style;

}
add_filter( 'ocean_page_header_style', 'my_page_header_style' );

/**
 * Alter your page header background image
 *
 * Replace is_singular( 'post' ) by the function where you want to alter the layout
 * Place your image in your "img" folder
 */
function my_page_header_bg_img( $bg_img ) {

	if ( is_singular( 'post' ) ) {
		$bg_img = get_stylesheet_directory_uri() . '/img/my-image.jpg';
	}

	// Retrun
	return $bg_img;

}
add_filter( 'ocean_page_header_background_image', 'my_page_header_bg_img' );

/**
 * Image position (optional)
 */
function my_page_header_image_position( $position ) {

	if ( is_singular( 'post' ) ) {
		$position = 'bottom center';
	}

	// Retrun
	return $position;

}
add_filter( 'ocean_post_title_bg_image_position', 'my_page_header_image_position' );

/**
 * Image attachment (optional)
 */
function my_page_header_image_attachment( $attachment ) {

	if ( is_singular( 'post' ) ) {
		$attachment = 'fixed';
	}

	// Retrun
	return $attachment;

}
add_filter( 'ocean_post_title_bg_image_attachment', 'my_page_header_image_attachment' );

/**
 * Image repeat (optional)
 */
function my_page_header_image_repeat( $repeat ) {

	if ( is_singular( 'post' ) ) {
		$attachment = 'no-repeat';
	}

	// Retrun
	return $attachment;

}
add_filter( 'ocean_post_title_bg_image_repeat', 'my_page_header_image_repeat' );

/**
 * Image size (optional)
 */
function my_page_header_image_size( $size ) {

	if ( is_singular( 'post' ) ) {
		$size = 'cover';
	}

	// Retrun
	return $size;

}
add_filter( 'ocean_post_title_bg_image_size', 'my_page_header_image_size' );

All PHP snippets should be added via a child theme's functions.php file.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.