WordPress.org

Ready to get started?Download WordPress

Forums

Live Wire
[resolved] Default featured image (5 posts)

  1. djj_
    Member
    Posted 1 year ago #

    It's pretty neat what the theme does, displaying a thumbnail if the post includes images. How would I go on setting some image as a default, in case the post doesn't have any?

    I found some guides on this subject but if I understood correctly, this Hybrid framework complicates matters a bit.

  2. Sami Keijonen
    WordPress-asiantuntija
    Theme Author

    Posted 1 year ago #

    You do it like this.

    add_filter( 'get_the_image_args', 'my_get_the_image_args' );
    
    function my_get_the_image_args( $args ) {
    
    	$args['default_image'] = trailingslashit ( get_stylesheet_directory() ) . 'images/example.png';
    
    	return $args;
    }
  3. Sami Keijonen
    WordPress-asiantuntija
    Theme Author

    Posted 1 year ago #

    Sorry there were little mistake in code snippet. Here it is again and in more detail. Put this code in child theme functions.php.

    This goes inside setup function.

    add_filter( 'get_the_image_args', 'my_get_the_image_args' );

    And this outside.

    function my_get_the_image_args( $args ) {
    
    	$args['default_image'] = trailingslashit ( get_stylesheet_directory_uri() ) . 'images/example.png';
    
    	return $args;
    
    }
  4. djj_
    Member
    Posted 1 year ago #

    Thank you! That's real elegant (and almost stupidly simple..) I am still learning, that much is obvious.

  5. Sami Keijonen
    WordPress-asiantuntija
    Theme Author

    Posted 1 year ago #

    All I can say that almost everything is filterable in the theme and naturally in Hybrid Core.

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic

Tags

No tags yet.