Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save florianziegler/ba9fd941e24c4a795c661d17fd7bb160 to your computer and use it in GitHub Desktop.
Save florianziegler/ba9fd941e24c4a795c661d17fd7bb160 to your computer and use it in GitHub Desktop.
Use a random picu collection image as background
/**
* Use a random collection image as background.
*
* @param string $custom_styles CSS code; Make sure to add your code to the string and not overwrite it.
*/
function my_picu_delivery_random_collection_background( $custom_styles ) {
$post = get_post();
$delivery_option = get_post_meta( $post->ID, '_picu_collection_delivery_option', true );
if ( $delivery_option == 'upload' AND ( 'delivery-draft' == $post->post_status OR 'delivered' == $post->post_status ) ) {
$images = get_post_meta( $post->ID, '_picu_collection_delivery_ids', true );
}
elseif ( 'draft' == $post->post_status OR 'sent' == $post->post_status OR 'approved' == $post->post_status ) {
$images = get_post_meta( $post->ID, '_picu_collection_gallery_ids', true );
}
if ( ! empty( $images ) ) {
$image_ids = explode( ',', $images );
shuffle( $image_ids );
$image = wp_get_attachment_image_src( $image_ids[0], 'thumbnail' );
}
if ( ! empty( $image ) ) {
$custom_styles .= 'body { background: url(' . $image[0] . ') fixed; background-size: cover; }';
}
return $custom_styles;
}
add_filter( 'picu_custom_styles', 'my_picu_delivery_random_collection_background' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment