25 May 2017

Timeline Express Pro: Announcement images as CSS backgrounds

A big thankyou to Evan Herman over at Code Parrots who helped me out with the following solution to an request that I submitted. He has developed a terrific timeline plugin for Wordpress, that is very flexible and looks super jazzy.

The following code displays the URL of announcement images rather than displaying the image as a HTML img tag. This is handy so that the URL can then be used to display the image as a CSS background image. Insert the following into your themes functions.php file.

And don't forget to show Evan some love. If you need a timeline plugin for Wordpress, Timeline Express is definitely the top pick of the bunch - and Evan provides prompt and professional support.


/**
* Return the announcement URL instead of the image markup
*
* @param string $announcement_image Original announcement_image image.
* @param integer $post_id The announcement ID.
*
* @return string The image URL
*/
function custom_announcement_image( $announcement_image, $post_id ) {

if ( is_single() ) {

return $announcement_image;

}

return get_post_meta( $post_id, 'announcement_image', true );

}
add_filter( 'timeline_express_image', 'custom_announcement_image', 10, 2 );