Shortcode to upload static image at top of page
-
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: https://360healthandperformance.com/news-room
I’d really appreciate any help!
Thanks,
Chris ShaySHORTCODE
/** * 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] https://360healthandperformance.com/wp-content/uploads/2010/10/News.png [/static_images]
- The topic ‘Shortcode to upload static image at top of page’ is closed to new replies.