• 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

Function to load an image

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 › Design Tips and Tricks › Function to load an image

This topic is: not resolved

Tagged: function, hook, image

  • This topic has 2 replies, 3 voices, and was last updated 10 years, 10 months ago by WisdmLabs.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • March 18, 2015 at 9:26 pm #144898
    NCKTessa
    Member

    I'm trying to add a full width image below the header image on a set of pages. I think I've sorted out how to do this by creating a page template in which to place the function, but I'm pretty new to actually writing the function code (as in, I just started researching it tonight). So far I have this:

    add_action( 'genesis_after_header' 'callback_function' );
    function callback_function() {

    the callback_function being whatever I need to do to bring in the image that's in my media library. Do I even need to define the function for this, or is there a simpler way to do it? Again, I will have loaded the image into the media library. Also, it will be the same image on every page. The sample URL will have a sidebar displaying once I have it set up right, and the image should be above the sidebar and content. Thanks!

    http://www.naturalcomfortkitchen.com/services/
    March 18, 2015 at 9:42 pm #144899
    Brad Dalton
    Participant

    Thats the start of the function done correctly.

    Then you can pull the image in using a variety of methods.

    1. get_stylesheet_directory_uri() is one you can use.

    2. Another option is to add backstretch conditionally after the header so your image stretches on different screen sizes. ( this solution requires membership )


    Tutorials for StudioPress Themes.

    March 18, 2015 at 11:43 pm #144902
    WisdmLabs
    Member

    Hello Tessa,
    If you want show an image from the media gallery you can use wordpress function wp_get_attachment_image_src( $attachment_id, $size, $icon );
    You can find more about this function at http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src

    you can create your callback function in following manner:

    function callback_function() {
      /**  
       *     You will have to replace $attachment_id with the actual attachment id of the image in your WordPress Database. 
       *     You can get this id by going to the media library page in your WordPress backend and in url 
       *     (http://example.com/wp-admin /upload.php?item=621)  the ?item= is the attachment id.
       */
    
       $image_attributes = wp_get_attachment_image_src( $attachment_id, 'full' );  
       if( $image_attributes ) {
         ?>
         <img src="<?php echo $image_attributes[0]; ?>" alt="full width image below header" />
         <?php
      }
    }

    You may also have to add a class to this image and add CSS as required.


    http://wisdmlabs.com/

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Design Tips and Tricks’ 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

© 2026 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