Default Featured Image

This topic contains 1 reply, has 2 voices, and was last updated by  Stephen Harris 9 years, 3 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #14310

    It would be nice if the feed settings included a default featured image. Is there any way to do this?

    Thanks!
    Susan

    Susan Giles
    #14319

    Hi Susan,

    This hasn’t really been a much requested featured, but there’s a couple of ways you can do this.

    You an use the actions eventorganiser_ical_sync_event_inserted/eventorganiser_ical_sync_event_update :

    add_action( 'eventorganiser_ical_sync_event_inserted', 'my_assign_thumbnail', 10, 3 );
    function my_assign_thumbnail( $event_id, $event_array, $feed_id ){
         //Check if event has thumbnail
         //Assign thumbnail based on $feed_it if not.
    }
    

    My preferred way, is the ‘just in time’ method. That is, when displaying the event thumbnail, if it doesn’t have one, use a default image.

    add_filter( 'post_thumbnail_html', 'my_post_thumbnail_html', 10, 2 );
    function my_post_thumbnail_html( $html, $post_id ) {
    
       if( 'event' != get_post_type( $post_id ) ){
             return $html;
       }    
    
       if ( empty( $html ) ){
            //Optionally set default image url (e.g. image in [theme-directory]/images/default-images.png
            //You can change this based on $feed_id:
            $feed_id = get_post_meta( $post_id, '_eventorganiser_feed', true );
            $html = '<img src="' . trailingslashit( get_stylesheet_directory_uri() ) . 'images/default-thumbnail.png' . '" alt="" />';
       }
    
        return $html;
    }
    

    Note that events are just posts and thumbnail handling is done entirely through WordPress’ thumbnail API. As such you can use all of WordPress’ thumbnail functions. Just not that Event ID ($event_id) is the post ID.

    Stephen Harris
Viewing 2 posts - 1 through 2 (of 2 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.