Solved issue of dynamic function name by using $shortcode var as function name
foreach ($shortcodes as $shortcode) {
add_shortcode($shortcode, function ($atts) use ($shortcode) {
$filepath = str_replace('_', '-', $shortcode);
ob_start();
require_once(get_stylesheet_directory() . '/template-parts/' . $filepath . '.php');
return ob_get_clean();
});
}
Related Posts:
- Listing and displaying WooCommerce Shipping Zones in the frontend? [closed]
- MySQL Query Returns Array () In Shortcode
- How can i iterate through this shortcode array?
- Return HTML Template Page with PHP Function
- Is there a way to parse shortcodes in PHP?
- Display sorting options dropdown when using WooCommerce product category shortcode
- Retrieve multiple values passed to a single attribute in a shortcode
- ob_get_clean returns empty string, ob_get_flush outputs string
- Export User Info to CSV from Front End
- Error in WP_update_post
- Add/echo div with Analytics-Code to function in functions.php
- How do I hardcode a WordPress shortcode into my theme?
- Looping through WP_Post Object
- Using a javascript file to access a get posts array
- How to return multiples lines in a shortcode?
- Generate an array of parent/child page IDs, based on parent page name
- How do I output a database option that is an array into a get_posts array?
- How do I turn a shortcode into PHP code?
- Check if term object is in array
- How to return a foreach inside a shortcode
- custom shortcode will not display the wrapped content
- Shortcode content output but not in correct place
- PHP code inside shortcodes
- Using a variable in is_page(array())
- Trigger popup in a php if/else statement
- Remove duplicates – array_unique()
- Append HTML Using Shortcode
- How to output a PHP file values by shortcode?
- get_the_tags() not iterating through for/while loop, but will with foreach
- get a simple array of all of the term names that exist in all taxonomies
- How to use $query->set with post__in?
- How to display data from custom table in wordpress phpmyadmin
- Reprinting tags with all attributes
- Creating own shortcode – echoeing php variable based on JS variable
- Checking array against author id in loop
- Redirect to another page using contact form 7? [closed]
- Get URL from shortcode tag
- echo something inside a shortcode
- Shortcode from a function not working
- Is it possible to return content, and then also continue to do other things?
- anyway to put inside a $outprint=sprintf()
- Creating WordPress Shortcode with Variable
- Catchable fatal error: Object of class stdClass could not be converted to string
- Could use some help with Shortcodes
- How to say if meta_value is greater than 0 in an array?
- Line breaks inside shortcode variable
- Loop over Array and get the distinct ids
- Remove empty terms from array, sort alphabetically, update back to repeating field
- Only show first image in foreach loop
- Shortcode for Listing Users from Meta Value?
- How can I get all values from my array in a loop in php? [closed]
- Get all posts as an array ID => Name
- Filter by field with array value in ACF on WP REST API
- Shortcodes showing in excerpt despite using strip_shortcodes
- Separate array output into a
- Calling PHP Titles inside Javascript Markup
- add the value of a variable returned in a while loop [closed]
- How to get my [shortcode] rendered on the home page, other pages are fine
- Including Custom fields within the_content
- Update value of a associative array with update_post_meta
- Show Featured Image Dimensions and size frontend with shortcode
- How to get woocommerce orders with get_posts method in a shortcode
- Counting number of posts in multiple (sub)categories using shortcode
- Convert a column of a table containing an Array as response in HTML
- Create an array with all the links of the years’ archive (of a custom post type)
- Redux option doensn’t seem when include from functions.php
- Display Visual Composer shortcode if a post belongs in specific categories
- is it possible for a URL to filter by tag
- Trying to create a shortcode to display categories with a specific product tag
- How can I prevent a shortcode div from extending beyond its boundaries?
- Adding variable in WordPress shortcode
- Display a custom name when the user has no name settle in his account
- Display one random image from Media Library
- Execute Shortcode in Textfile
- Echo short code syntax
- custom taxonomies not working
- How to return html as a string from php for WordPress
- Changing Date Format on Custom Meta Data w/shortcode call
- Add the shortcodes from the enfold theme to the other theme
- Offset with ajax load more posts duplicates
- get_category_parents to array
- Shortcode in a $output statement
- Need help with PHP functions
- When using shortcode, content stops generating after the_content
- PHP Shortcode – 500 error
- Run PHP Results inside WP Shortcode
- Shortcode At top of Page – PHP 5.5 vs 5.4 – ob_start();
- Non-array argument in array_merge()-function [closed]
- On selecting shortcode generate selected shortcode table inside page editor worrdpress
- Using the same shortcode to show any table from the database
- Shortcoding with Divs
- Showing all post from all post type in admin backstage
- My title is showing after the shortcode
- Use php array outside his function
- Shortcode to include PHP file, pass various parameters to include?
- Retrieve Array from within Array [closed]
- HTTP 500 Error after Creating Shortcode
- How to group by column a and sum column b and c in a php array
- How to execute a shortcode within a custom field?
- PHP how to submit array elements to database