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?
- Shortcode to show the code
- Shortcode returns values in the wrong order
- Redirect to another page using contact form 7? [closed]
- Get URL from shortcode tag
- Embedding PHP in shortcode $content
- Alter required message using comment form api
- Shortcode with PHP issue “Undefined index”
- Excecuting php function in shortcode
- Advanced Custom Fields – display label and value only if value entered
- Only first shortcode gets executed
- meaning of (array)function()
- Multiple do_shortcode in page template
- Grouping posts by a custom meta value
- Returning data instead of echoing/printing
- echo something inside a shortcode
- displaying content that includes shortcodes within an echo
- wp_force_remove_style’ not found
- List taxonomy term slugs within shortcode (do_shortcode)
- Shortcode from a function not working
- Display Data in Table from External Database in WP using Shortcodes
- get_posts works in the page template but not in a shortcode
- Is it possible to return content, and then also continue to do other things?
- How to fix this warning:call_user_func_array() expects exactly 2 parameters, 1 given in D:\wamp\www\…….\wp-includes\class-wp-hook.php on line 286
- How can I access string value in an array?
- ::before on open/close function [closed]
- anyway to put inside a $outprint=sprintf()
- How to use if statement in an array? [closed]
- How to array only one key from another array
- Is There A Way To Make Theme Files Accept Shortcodes?
- Filtering a function’ output for a new continued function
- How can I include shortcodes within PHP?
- 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]
- Get html data with javascript to php array and store to wordpress database
- do_action(), iFrame Gets Displayed Despite Password Protection [closed]
- $wpdb returns duplicate posts
- Creating WordPress Shortcode with Variable
- Catchable fatal error: Object of class stdClass could not be converted to string
- Syntax error in a shortcode function
- Using Shortcode to Grab Archive Listing, Separate by Year
- Capitalize Shortcode Value on Output
- How do I create a numbered list with PHP? [closed]
- Shortcode to find and replace URL
- Why is my str_replace not working on short code submitted by front-end?
- Why is an array created in a function hooked to customize register populated when customizer is loaded but not when the front-end is loaded?
- Could use some help with Shortcodes
- How to put a form with php code into a variable or shortcode?
- How to use array in function to get only value I want
- Error while setting role
- Get categories names as an array to use it in theme settings
- Unable to process php via shortcode
- Help with WordPress function inside a shortcode
- calling a custom field value inside functions.php
- How to get the last category name of a child category?
- Using ob_start and ob_get_clean with wordpress shortcode
- How to say if meta_value is greater than 0 in an array?
- How to use two meta_compare in an array?
- Warning: in_array() null given in PHP function
- Short code template + ajax
- WordPress shortcode returns the data before
- Foreach loop inside an array_merge
- List all blogs, but exclude the main site
- Shortcode to embed Edit Account form not working
- Shortcode not staying inside div tag
- Line breaks inside shortcode variable
- Loop over Array and get the distinct ids
- How to access or parse key/values that have “string”
- If Array Values Match Another Array’s Values, Then
- Remove empty terms from array, sort alphabetically, update back to repeating field
- WordPress loop by meta key that is an array? and how loop multiple arrays
- Only show first image in foreach loop
- Handling PHP/HTML inside the output of a shortcode function
- Shortcode for Listing Users from Meta Value?
- Conditional multidimensional arrays and array_map
- Cant display an image via PHP in wordpress
- Shortcode to pull posts
- How can I get all values from my array in a loop in php? [closed]
- Getting posts to exclude from array
- Get all posts as an array ID => Name
- I’m unable to call img path using single quotes in an array?
- PHP code inside Shortcode
- Filter by field with array value in ACF on WP REST API
- extract serialized array to use for wp-query
- Need to Modify a WordPress Shortcode with another wordpress shortcode
- Help Fallback (thumbnail)
- get users search not working with array
- How to return a string that has a jQuery and Ajax inside in a shortcode?
- Comapare get_user_meta value
- How can get all users by current user meta?
- Get the id of all images in a post
- Shortcode to log user into current URL
- Shortcode function doesnt work without caption
- Action Hook Inside WordPress Plugin Shortcode
- Output category list inside array
- How can I include the user id inside of a shortcode php output?
- how to make an array of post id’s in is_single
- Split shortcodes to array of shortcodes