• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Suggestion to change Genesis source code

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Suggestion to change Genesis source code

This topic is: resolved
  • This topic has 1 reply, 2 voices, and was last updated 10 years, 12 months ago by Davinder Singh Kainth.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • December 13, 2014 at 2:22 am #134449
    Carlo
    Member

    This concerns Genesis 2.1.2

    The function I don't like is genesis_get_image in genesis/functions/image.php.

    I want to set a default fallback image to display if there is no post thumbnail. As it is, the way the function allows me to do that is with the genesis_get_image_default_args filter. See lines 78–83 of genesis/functions/image.php:

    	/**
    	 * A filter on the default parameters used by <code>genesis_get_image()</code>.
    	 *
    	 * @since unknown
    	 */
    	$defaults = apply_filters( 'genesis_get_image_default_args', $defaults, $args );

    The default arg I need to filter is fallback, which must be an array containing the complete HTML for the image, as well as its URL. See lines 104–109 of genesis/functions/image.php:

    	//* Else if fallback array exists
    	elseif ( is_array( $args['fallback'] ) ) {
    		$id   = 0;
    		$html = $args['fallback']['html'];
    		$url  = $args['fallback']['url'];
    	}

    Then my filter will look like this:

    //* Set default post thumbnail
    add_filter( 'genesis_get_image_default_args', function( $defaults, $args ) {
    	$defaults[ 'fallback' ] = array();
    	$defaults[ 'fallback' ][ 'html' ] = wp_get_attachment_image( DEFAULT_IMAGE_ID, $args[ 'size' ], false, $args[ 'attr' ] );
    	list( $defaults[ 'fallback' ][ 'url' ] ) = wp_get_attachment_image_src( DEFAULT_IMAGE_ID, $args[ 'size' ], false, $args[ 'attr' ] );
    
    	return $defaults;
    }, 10, 2 );

    My gripe about supplying an array with HTML and URL is that I have to hard-code the calls to wp_get_attachment_image and wp_get_attachment_image_src. I would rather supply an attachment id for the default post image, and have Genesis handle the calls to wp_get_attachment_image and wp_get_attachment_image_src in case things change in a future version.

    So the filter I would like to be able to write is as follows:

    //* Set default post thumbnail
    add_filter( 'genesis_get_image_default_args', function( $defaults ) {
    	$defaults[ 'fallback' ] = DEFAULT_IMAGE_ID;
    	return $defaults;
    } );

    And below is my proposed change to the function genesis_get_image. It basically allows the fallback arg to be the id of an attachment, while still retaining backward compatibility for the array format. This replaces lines 92–113 of genesis/functions/image.php:

    	//* If post thumbnail (native WP) exists, use its id
    	if ( has_post_thumbnail( $args['post_id'] ) && ( 0 === $args['num'] ) ) {
    		$id = get_post_thumbnail_id( $args['post_id'] );
    	}
    	//* Else if the first (default) image attachment is the fallback, use its id
    	elseif ( 'first-attached' === $args['fallback'] ) {
    		$id = genesis_get_image_id( $args['num'], $args['post_id'] );
    	}
    	//* Else if fallback id is supplied, use it
    	elseif ( is_int( $args['fallback'] ) ) {
    		$id = $args['fallback'];
    	}
    
    	//* If we have an id, get the html and url
    	if ( isset( $id ) ) {
    		$html = wp_get_attachment_image( $id, $args['size'], false, $args['attr'] );
    		list( $url ) = wp_get_attachment_image_src( $id, $args['size'], false, $args['attr'] );
    	}
    	//* Else if fallback html and url exist, use them
    	elseif ( is_array( $args['fallback'] ) ) {
    		$html = $args['fallback']['html'];
    		$url  = $args['fallback']['url'];
    	}
    	//* Else, return false (no image)
    	else {
    		return false;
    	}

    As far as I know, Genesis does not actively encourage developers to submit suggested source code changes like WordPress does, but I think the above change makes a lot of sense and I would like to have it considered for inclusion.


    Comprehensive, easy to follow Genesis documentation

    December 14, 2014 at 8:51 am #134505
    Davinder Singh Kainth
    Member

    Best would be contact studiopress team - http://www.studiopress.com/contact

    Or reach Brian Gardner directly here - http://www.studiopress.com/contact or on his Twitter profile.


    Sunshine PRO genesis theme
    Need Genesis help? Davinder @ iGuiding Media | My Blog | Fresh Genesis Themes

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble