Are you going to put newlines in there between each image? or just spaces?
I’ll put in both for this example, checking if there’s a newline.
You would want something like this in your functions.php:
add_shortcode('my_gallery', 'gallery_function');
function gallery_function($atts, $code=""){
$files=preg_split( '/\s+/', $code ); // Added in from Jan's comment.
foreach($files as $img){
if($img=="")
continue; // ensures that no empty items from the split have entered in, since that is possible with the preg_split
//handle each filename in here.
}
}
It’s not perfect.. if you use both spaces and newlines in your shortcode, it’ll mess things up – though that could be dealt with in more detail inside the function.
Hope this helps.
Related Posts:
- How to manually fix the WordPress gallery code using PHP in functions.php?
- Adding Image Count to Multigallery
- Showing a different gallery in a seperate post
- Create shortcode for metabox gallery
- Encode text string being appended as query to URL [closed]
- How to draw media details for Isotope gallery using Photoswipe
- PHP/Manual use of images? – 2 Questions
- Display a text message if the shortcode is not found?
- How to return a string that has a variable inside in a shortcode?
- Run shortcode at certain resolution
- Passing a shortcode attribute to a sub-function
- post meta value as shortcode parameter
- How to protect own PHP code from WordPress updates
- Get list of shortcodes from content
- Loading page template into shortcode
- How to add Shortcode (font awesome) in widget title?
- Placing the_content inside shortcode not working
- Autogenerate shortcodes from an array of strings
- How do I add text in a shortcode?
- How to Insert Shortcodes into Theme?
- is_page “range” for if statement?
- How can I generate random numbers inside my shortcodes on each implementation?
- Shortcode content filter?
- Custom Theme, Custom shortcode not working
- Why is file_get_contents returning page source?
- Plugin CSS not enqueing
- Different loop output every x posts in custom post type
- Showing content from one page on another
- Get value from shortcode to do something
- Custom shortcode outputs plain text instead of HTML at top of post
- How to use wp_add_inline_style for custom CSS added via shortcode?
- Custom gallery in wp3.5
- Shortcode returns values in the wrong order
- Embedding PHP in shortcode $content
- Shortcode with PHP issue “Undefined index”
- Excecuting php function in shortcode
- Returning data instead of echoing/printing
- ::before on open/close function [closed]
- Is There A Way To Make Theme Files Accept Shortcodes?
- Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
- Create a WordPress shortcode using PHP [duplicate]
- do_action(), iFrame Gets Displayed Despite Password Protection [closed]
- Using Shortcode to Grab Archive Listing, Separate by Year
- Unable to process php via shortcode
- Timthumb.php image gallery not working on Multisite WordPress
- calling a custom field value inside functions.php
- Using ob_start and ob_get_clean with wordpress shortcode
- List all blogs, but exclude the main site
- Change default gallery images – Currently they are displaying full size imagese
- Cant display an image via PHP in wordpress
- PHP code inside Shortcode
- Action Hook Inside WordPress Plugin Shortcode
- How can I include the user id inside of a shortcode php output?
- How do I increase the upload size only when editing special pages?
- PHP Helper Class to create shortcodes
- help with custom shortcode that stopped working
- Auto create Nextgen Gallery on post creation [closed]
- Can ‘Custom Field’ data be inserted into this Short Code?
- how to get sentence values from wordpress shortcode parameter?
- Updating Metadata with Shortcode
- couldnt show short code atts in category
- Gravity Forms: How to add PHP function to confirmation conditional shortcode?
- wpdb->query returns different value to phpMyAdmin
- Time Stamp In A WordPress Post Title That Does Not Keep Refreshing
- How can I edit the final HTML structure of the whole web page
- I am having an issue with this shortcode plugin.. Warning: Illegal string offset ‘title’
- Advanced Custom Forms PHP formatting for do_shortcode
- ACF Gallery field images donwload
- overwrite wordpress gallery with custom gallery shortcode
- add custom link to gallery images
- How can I create a shortcode from an html and php code written together
- CPT in a shortcode
- PHP/CSS: Shortcode won’t display correctly, and only displays in the head (before content)
- Open/closed function [closed]
- What is wrong with this shortcode? to include external php file in WordPress posts
- Need to Echo A Url path to show on a wordpress page
- WordPress Shortcode based on other shortcode
- Force ‘permanent’ post cache of shortcode results
- Wrapping shortcode content in a span or link
- Formatting Shortcode to Display in Visual Mode
- Use html tags in shortcode_atts, is it real?
- How to pass parameter that ends up being part of a class name with wordpress shortcode
- Contact form field in wordpress menu
- How to have Function of a plugin using global vars into a shortcode?
- Creating image gallery in wordpress
- Overwriting a Shortcode
- Gallery requires a featured image but does not show it in posts/pages
- Where to place PHP for shortcodes
- How to wrap a text with shortcode into php file?
- PHP Widget and do_shortcode
- Shortcode not passing variable to included file
- A next page function with shortcode?
- using a shortcode in a hyperlink
- How to create shortcode of this PHP code
- WP Custom tables query
- Display total count of products in orders of a specific order status
- Gutenberg – render_callback does not pass ToggleControl value on frontend
- HTTP 500 Error after Creating Shortcode
- How call WordPress shortcode inside function file
- How to execute a shortcode within a custom field?