Visual Composer adds the image ID to the generated shortcode. This gives you more flexibility with image sizes. You can use it like this:
$imageSrc = wp_get_attachment_image_src($image_url, 'thumbnail');
if( $imageSrc ) {
echo '<img src="' . $imageSrc[0] . '" />';
}
The thumbnail
param could be replaced by medium
or another valid image size. The if
clause is there to verify that the image is really there (not deleted).
Advice: Rename the param_name
to image_id
so you won’t get confused when using the code later.
Source: https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/
Related Posts:
- Remove images from get_the_excerpt
- Need to convert image url to a Base_64 data url with wordpress function..
- Missing feature image link function
- Solution to render Shortcodes in Admin Editor
- Include PHP file in Content using [shortcode]
- How to change the markup WordPress inserts for post images
- Programmatically Set First Image as Featured
- Shortcode producing headers already sent error
- WP 4.4. responsive loads normal image after loading the responsive image
- Enabling shortcodes for custom fields
- How to reduce original image quality on upload?
- How to use get_media_embedded_in_content function
- Shortcode with parameters inside parameters
- Set image size on media and text block with a function
- What is wrong with this Shortcode? I get it in a wrong place inside the content
- Display random text from a file with the WP built-in AJAX API
- Set first oembed in post to a global variable or function
- Create thumbnail on PDF upload with Gravity Forms
- Use Exact Image Size using add_image_size
- Adding body class when post contains a specific shortcode
- Insert width & height attributes to all images displayed on each page
- Overwrite Parent Theme add_image_size in Child Theme
- Images uploaded using media uploader are appearing upside down
- How to add css class to image attached in all the posts?
- Add custom image size not working
- Detect Safari desktop browser and include the detection in a shortcode
- My simple custom shortcode is not longer working (possibly due to upgrade to WordPress 4.4 ?)
- how to add an image to the footer?
- wp_get_attachment_image function size argument not working if I also add a custom class
- Display first name of logged in user?
- WordPress shortcode attributes for database SELECT?
- Understanding and altering the structure of posted images
- Shortcode inserts paragraphs before and after executing shortcode
- Publish/Update post is changing image links from file url to post url
- Featured Image Thumbnail Creation
- Display images that are not in the content
- show first 3 thumbnails of posts in different sizes [closed]
- How can I make a widget shortcode to control all the widgets?
- Getting custom image size URL in functions
- Passing variable as add_shortcode argument
- Add button to kitchen sink toggle
- Control the srcset much more (not all sizes in it each time)
- Shortcode parse error – wrong syntax
- Testing for a shortcode using a function. 404 page throwing PHP Notice
- How to hide image-url if no attachment?
- Woocommerce checkout field
- How to properly set custom logo size?
- How can I pass a shortcode value to the head in wordpress functions.php
- Native gallery custom html output
- dynamic site link for future migration in echo do_shortcode()
- Need a method to prevent WP from adding in between my shortcodes
- Load scripts for do_shortcode( ‘ [ my_shortcode ] ‘ )
- Image Crop Not Working
- Use existing image sizes for WooCommerce
- Problem in using Customizer
- wp_get_attachment_image_src returns image on main domain, false on subdomain
- Retrieve First Image Function
- Featured Image keeps cropping
- Prevent creating multiple image resizes in twentytwelve template
- Shortcode of a function
- Conditional function for excluding first image from content, not working
- How to add a shortcode to call a function
- How can I call a PHP function inside a hardcoded shortcode?
- Elementor Pro display featured image on section -> style -> image using shortcode
- Is it possible to create a shortcode to link to a specific post/page where the tag is just an attribute?
- Different image using srcset function
- How to add if statement on WordPress shortcode output
- Is it possible to limit number of files a non-admin user can upload via the WordPress media library?
- Auto delete content in specific folder inside media library
- Pagination not working – FrontPage
- How to update an image attachment’s alt text from a custom field when saving a post?
- Function to function shortcode help [closed]
- large image size of 1440×1440 not pulling 2x of 2880×2880 image
- I want to display the sku in the product pages of my EDD website
- Can You Set A Minimum Image Dimension For Resizing Images?
- Shortcode to insert default text and change one word throughout it?
- (Divi): How to make WordPress load images of specific size for Blurb modules on given page with a funciton?
- use add_action in a shortcode (gravity form – WordPress)
- Shortcode displaying outside the div [duplicate]
- Shortcode Initialization in a Custom Theme
- Shortcode with pagination advancing multiple queries
- Show users last read posts for each user?
- Get shortcode attribute value to another function
- Hide disclaimer from summary excerpts
- restrict uploaded image size and fixed image display size
- Function not receiving string from shortcode
- Using Switch Statement to Change Image According to Last Digit of Topic ID
- Disable links to images only if link is an image
- Restricted images only for logged user. (hidden url)
- Shortcode to eliminate and replace with
- Different body image backgrounds on different pages, posts and categories
- Problem in outputting shortcode
- Open image size links in a page instead of direct image link
- Shortcode to output get_header not working
- using enqueue_script in a shortcode isn’t working
- Function to get thumbnail img source
- Shortcodes not outputting in correct divs
- trouble with passing class method data to outside function
- Get term count on a category page
- How do grab the main loop, with conditions, and output via shortcodes