You can use a closure for that together with the use
keyword. Simple example:
$dynamic_value = 4;
add_shortcode( 'shortcodename',
function( $attributes, $content, $shortcode_name ) use $dynamic_value
{
return $dynamic_value;
}
);
See also Passing a parameter to filter and action functions.
Related Posts:
- How to create a shortcode with 1 parameter (atts)
- Add attribute to existing Shortcode
- Get URL Param Plugin and Inserting Result in Widget Code
- Problem parsing long parameter in shortcode
- Shortcode not interpreted if parameter set
- How to display a page dependent on a url parameter supplied by a form/button page?
- Is it possible to change a shortcode parameter based on a media query?
- How to handle Ajax Calls, when using same shortcodes (with different parameters, e.g. ‘post-type’)?
- Enqueue Scripts / Styles when shortcode is present
- how to show the syntax of a shortcode
- Get first video from the post (both embed and video shortcodes)
- Wordspress add into my javascripts
- Using preg_replace to separate gallery from the_content?
- List of all inbuilt WordPress shortcodes
- shortcode outputs first before the page content [duplicate]
- Shortcode attribute value with dash (hyphen)
- Shortcode content does not show in feed discription/excerpt
- Adding shortcode inside Visual Composer raw HTML [closed]
- Shortcode not working inside html input
- do_shortcode based on _thumbnail_id
- Why does WP not like my container?
- Nested Shortcode Inside [caption] Doesn’t Process
- How can I get the [video] shortcode to allow query string parameters?
- How to link to a alternative page in CSS
- How to handle a shortcode function directly?
- Turn a snippet of HTML and PHP into a shortcode
- How can I get the current user email instead of user ID?
- How to put an “include” inside a “do_shortcode”?
- Changing playlist shortcode thumbnail sizes?
- Shortcodes output in the wrong order
- Adding short codes from a page’s content on header and hiding the same from page’s content
- Should I cache default WordPress gallery shortcode output?
- WordPress 4.7 Galery shortcode not working
- How to add and submit input fields using a shortcode?
- How can i remove the paragraph from shortcodes content?
- Easy way to show excerpts of specific posts on a page
- Pass javascript array to shortcode
- Shortcode content not displaying on Home page
- shortcode causing the_content() to return blank?
- WordPress shortcode display as plain text
- Replace / Remove Shortcode after 1st run / post
- What is wrong with my rewrite rule for a page URL with query parameters and short codes?
- WordPress Shortcode callback function with a plugin
- Can I wrap an unordered list inside a shortcode?
- How do I write this shortcode? [closed]
- WordPress shortcode for a section Template
- Saving post content to database with do_shortcode?
- Is it important to sanitize inputs in a shortcode that will be used in site that only I will post to?
- Shortcode default attributes over-riding non-default attributes
- Shortcode callback for add_action(‘wp_footer’)
- Using shortcode to display array in array
- Add the last viewed post title to a contactform with shortcode [closed]
- Make a Shortcode load after Post/Page Content?
- Adding a template part as part of a shortcode
- Just display content between shortcode brackets
- How can i share codes on my blog?
- How to explode single string IF it’s used in shortcode
- Check if CTP category taxonomy is set in shortcode
- Getting Page Content Using Shortcode
- how can i pass this attribute in this shortcode?
- How to add a same div on every page
- Get param from shortcode in plugin function
- Display a form partially with a shortcode
- Modifying the wordpress login page and then referencing it with a shortcode problem
- How to make shortcode which returns HTML?
- Render shortcodes with get_post_custom
- How to create a custom shortcode for custom login form?
- Pass a comma separated shortcode attribute to a function
- how to write short code in word press
- Set redirect for need login
- make user_id in a shortcode dynamic based on who’s logged in
- pass complex json as shortcode parameter
- Image Caption Shortcode Broken upon update
- Shortcode not working in CPT taxonomy
- wp_enqueue_scripts does not work on admin page
- shortcode containing other shortcodes not returning content
- To know whether insert shortcode in custom meta box
- Shortcodes not working in custom page
- Get label in user meta query
- Shortcode not being executed
- Load gravity form via ajax using do_shortcode
- Video Short Code and Media Fragments URI
- How to process a single attribute in a SQL request twice times?
- Customise standard lists within my shortcode
- How to fix transparency in product sliders / featured products on home page?
- Pull in excerpt with shortcode
- Short code format for cat tagging when posting from email
- How do I use “while” and “end while” inside of the echo do_shortcode with ACF Repeater?
- Problem in creating a shortcode form custom post type slider
- Add an access code form to call a unique page based on page without registration
- add php shortcode in return function
- Display post_meta in Shortcode
- style css to header for shortcodes
- WordPress Shortcode loads at the top
- What does this shortcode do?
- php code to shortcode [duplicate]
- How to stop an image link continuing to link adjacent text from a shortcode?
- create shortcodes for posts
- How Do I create a shortcode to dispaly a go to top button on any page or post
- 3 shortcodes 2 won’t render [closed]