WordPress.org

Ready to get started?Download WordPress

Forums

Shortcode to upload static image at top of page (2 posts)

  1. Chris S
    Member
    Posted 3 years ago #

    Hi!
    I am working with the AWAKE theme, but needed to add functionality that would allow each page to upload a (different) static image 980 px x 270 px that didn't have the moving 'slider' function.

    I wrote the following shortcode to upload an image to the header area. I am a bit out of my depth here, but I pasted the shortcode into my shortcode.php file and finally enough of the bugs out of it so that the site would load.

    The problem with this is that I'm not getting the image to load. Can anyone tell me what I am doing wrong? Do I need to define $image_url ? If so, how do I do that?

    Before the shortcode, I've pasted the pagecode I was using to implement this code on my page.

    Here is the result I'm getting: http://360healthandperformance.com/news-room

    I'd really appreciate any help!
    Thanks,
    Chris Shay

    SHORTCODE

    /**
    * Static Image Shortcode
    *
    * @param array $atts User defined attributes in shortcode tag
    * @param string $content Optional. Shortcode content.
    * @return string HTML content to display static images
    */
    function static_images( $atts, $content = null ) {
    global $post, $wpdb;
    $post_title = get_the_title($post->ID);
    
    extract(shortcode_atts(array(
    'title' => '',
    'alt' => '',
    'height' => '270',
    'width' => '980',
    ‘src’ => '',
    ), $atts));
    
    $out .='<div>';
    $out .= '<img class="staticimages" title="' .$title. '" alt="' .$alt. '" height="' .$height. '" width="' .$width. '" src="' .$image_url. '" />';
    $out .= '</div>';
    
    return $out;
    
    }
    add_shortcode('static_images', 'static_images');

    PAGE CODE

    [static_images]
    http://360healthandperformance.com/wp-content/uploads/2010/10/News.png
    [/static_images]
  2. Chris S
    Member
    Posted 3 years ago #

    Hi! I think I've fixed that problem. I looked hard at the code and came up with the following. It uploaded an image! Now if I can just fix the spacing around the outside. ... I'll mess with the CSS.

Topic Closed

This topic has been closed to new replies.

About this Topic