WordPress.org

Ready to get started?Download WordPress

Forums

Avatar To Replace A Custom Post Format Image (1 post)

  1. joegmaine
    Member
    Posted 1 year ago #

    Hoping someone might be able to help me sort this out. I'm running a Genesis child theme which has custom post format images and would like to replace the default image in the function with the authors avatar.

    Here's what I have in my functions.php

    add_action( 'genesis_before_post_title', 'genesis_do_post_format_image2' );
    function genesis_do_post_format_image2() {
    
    	global $post;
    
    	/** Do nothing if post formats aren't supported */
    	if ( ! current_theme_supports( 'post-formats' ) || ! current_theme_supports( 'genesis-post-format-images' ) )
    		return;
    
    	/** Get post format */
    	$post_format = get_post_format( $post );
    
    	/** If post format is set, look for post format image */
    	if ( $post_format && file_exists( sprintf( '%s/images/post-formats/%s.png', CHILD_DIR, $post_format ) ) )
    		printf( '<a href="%s" title="%s" rel="bookmark"><img src="%s" class="post-format-image" alt="%s" /></a>', get_permalink(), the_title_attribute( 'echo=0' ), sprintf( '%s/images/post-formats/%s.png', CHILD_URL, $post_format ), $post_format );
    
    	/** Else, look for the default post format image */
    	elseif ( file_exists( sprintf( '%s/images/post-formats/default.png', CHILD_DIR ) ) )
    		printf( '<a href="%s" title="%s" rel="bookmark"><img src="%s/images/post-formats/default.png" class="post-format-image" alt="%s" /></a>', get_permalink(), the_title_attribute( 'echo=0' ), CHILD_URL, 'post' );
    
    }

    What I want to do is display the authors avatar in this section of the function.

    /** Else, look for the default post format image */
    	elseif ( file_exists( sprintf( '%s/images/post-formats/default.png', CHILD_DIR ) ) )
    		printf( '<a href="%s" title="%s" rel="bookmark"><img src="%s/images/post-formats/default.png" class="post-format-image" alt="%s" /></a>', get_permalink(), the_title_attribute( 'echo=0' ), CHILD_URL, 'post' );

    If this was something I could handle in a theme template but the logic to determine what is displayed takes place here instead so that's not an option. Everything I try to swap out in that section breaks the site so I've hit a roadblock.

    Any help appreciated. Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic