You should use paths with glob
, not URLs.
But src
attributes needs URLs.
So something like this should work:
$base_dir = trailingslashit(get_template_directory());
$dir="img/services/";
$images = glob($base_dir.$dir.'*.png');
foreach($images as $image) {
$url = get_theme_file_uri($dir.basename($image));
printf('<div class="dynamic item"><img src="https://wordpress.stackexchange.com/questions/288995/%s" alt=""></div>', esc_url($url));
}
Where I make use of:
get_template_directory
To obtain the root path of (parent) themebasename
to obtain just the file name of the current image file pathget_theme_file_uri
to obtain the full URL of the image, in a child-theme friendly way: if the image is found in child theme it will be used from there, otherwise will be used from parent theme.
Related Posts:
- Remove update nags for non-admins [duplicate]
- Are WordPress Heartbeat API ‘beats’ staggered or do they occur simultaneously for all users?
- How to correctly add Javascript in functions.php
- Genesis – Customize search form
- Set media upload attachment link to none and hide it in WP v3.5
- Integrating WordPress to my website, while keeping my own authentication system
- Why does this echo values in the wrong order?
- Update Custom Field on Imported Post Creation
- Print out WordPress user ID – two sites with same code but different output
- Get value of contact form 7 radio button [closed]
- Initiate only latest version of a class
- Check if a user already voted [closed]
- Uncaught TypeError: Cannot read property ‘firstChild’ of null after upgrading to WordPress 5.5
- WordPress if (is_page) translation on certain page
- Uploading video to google drive via frontend [closed]
- Batch update a post meta field value of each post in Post Type
- Create dynamic pages from external JSON data without storing in Database?
- How to restrict wp generate attachment metadata() to certain intermediate image sizes
- Setting All Drafts to ‘exclude-from-catalog’ in WooCommerce
- How to properly insert a link to a template in WordPress?
- Difference between ‘type’ => ‘text’ and WP_Customize_Control
- Locating Global Variables
- database interactions using OOP
- get post based on category chosen in drop down – The ajax method
- Extending the WP_Widget_Text class
- Set the background to a default image if there isn’t a specified “featured image”
- WordPress Access allowed to fewer pages till user logs in
- How to pass aa JS variable to PHP?
- Display FNumber (aperture) as a number versus a fraction
- different id for same element visual composer [closed]
- user_profile_update_errors hook not executing
- Changing the default object embed sizes?
- Please help me with tag and php code [closed]
- Custom Theme’s “Preview Changes” Doesn’t Work for Previously Published Posts
- Get URL from shortcode tag
- Display WordPress Post Content in 3 Columns
- WordPress Stripping Colons?
- src script only works on home page?
- Could use some help with Shortcodes
- Should I use WordPress to skin a database website?
- wp_delete_comment takes two tries to delete – then deletes all comments
- WordPress Custom SQL Table with UserID Filter for results
- How to define a variable already defined in a plugin function?
- Array to string conversion on array_map
- Target post_date_gmt if it’s empty or not set
- Remove page title in product page using a function
- woocommerce specific quantities for product
- How to end a while loop when used in a fetch assoc function [closed]
- Output votes to div dynamically in wordpress
- Menu Custom Data Attributes
- Pass return-path additional parameter in wp_mail
- How to get image from url from the database?
- Separate array output into a
- How to override a plugins script
- Angular not defined [closed]
- Why in this WordPress theme I can’t see the Main Menu?
- Front end file upload returning wrong attachment url
- Comparing Dates from custom field
- Page load timer?
- Restrict post to current user in postmeta
- How to sort posts by active category in WordPress?
- wordprees multi-site in user panel add filter
- Database SQL query error
- How do I know if the user is a customer?
- WordPress custom php script to match standard page layout
- copy fields value to another field
- MYSQL TIMESTAMP when adding DATE_FORMAT then the output is blank, PHP conflict?
- How can one safely add html code to a wordpress theme header file?
- Plugin won’t output characters with diacritics properly
- WooCommerce is_product_category() not working
- Get parent category name when only child category is applied to a product
- ACF relationship on user profile page used for allowed access
- Retrieving and Displaying Data From a Table
- Error `this set of changes has already been published`
- Where does php code to load data go?
- How to locate parent theme functions and add functions to my wordpress child theme?
- Adding product permalink on admin order page throwing error
- Modifying child theme’s header
- Before & After Content – After Content directly below Before Content when using require_once
- How to create dynamic templates?
- How to create an unordered list of images separate from the content
- Top Authors list by highest post views with Ajax pagination
- How to add delete, approve, spam Links to Comments
- Gravity Forms on submit return value on same page
- How can i put php code on the wordpress page?
- Showing the authors username and bio on custom author.php
- Order by in foreach
- Help with my first Metabox helper class
- Splash pages on a high traffic site
- Query seems to be duplicated
- Dropdown Menu for Query_Posts
- ISOTOPE – Missing/Invalid Arguement Get Terms
- Fatal error: Uncaught Error: Call to undefined function wp_nav_menu()
- Add Condition if WPBakery Page Builder Used on Page or Not
- Add multiple HTML attributes to an Elementor button
- Customize the summary table of an order in the email
- How to sort custom sortable column by custom table value
- How to disable page create for custom post type, but allow a page with the post types slug to be created?
- WooCommerce Modal Fly cart on add to cart – With AJAX
- /page/2/ redirect to 404