Set a flag like $already_run
to static and give it an initial value false
. Then check if that value is true. If not, do the one-time thing and then set $already_run
to true
. The next time this function is called, it will not re-assign the static property, but will instead use the value set at end of code. So it will skip second and subsequent calls.
function foo_add_player($atts) {
static $already_run = false;
if ( $already_run !== true ) {
// do stuff here
}
$already_run = true;
}
Related Posts:
- Conditionally Loading JavaScript/CSS for Shortcodes
- Show shortcode without executing it
- shortcodes output before content [duplicate]
- Run visual composer code in php page
- WordPress adds br in between my shortcode
- Shortcodes, HTML tables, and multiple rows
- Audio or playlist shortcode condition according to the amount of files on attachment page
- Does a shortcode with a single attribute have to use an array?
- Shortcode to Gutenberg-block: additional text on front-end and conditional display
- How navigation works in custom loop within shortcode?
- Use [shortcode=”value”] instead of [shortcode att=”value”]?
- I dont want to show shortcode in tag
- Post loop created via shortcode not displaying shortcode in content
- Pass shortcode variables to template
- passing multiple parents value into a shortcode
- Is it possible to add a repeater field to TinyMCE’s option window?
- Shortcodes: Pros and Cons
- esc_attr not working in shortcode
- Raw output (preventing wpautop)
- Conditionally loading Facebook PHP SDK in shortcode
- Can’t understand $atts in functions?
- Are .MP3 files with capital letter extensions allowed in [audio] shortcode?
- How to handle shortcodes when using the JSON API
- Are shortcode functions applied while rendering the content, or are they executed and stored with the post content?
- is_admin() returns false in save_post hook with Gutenberg editor
- Get Posts shortcode plugin and meta_query?
- possibility to control embedded video timeline with buttons and links external to the player
- Get shortcode attribute outside of WordPress
- Overriding shortcode $atts for featured products
- How to create a shortcode for embedding pdf in iframe?
- Woocommerce, ordering products by default on shortcode pages
- detect when shortcode ran for the last time
- How can a shortcode can take the place of the featured image in a post?
- Looking for a way to include/embed text from a file on a page so that the short codes are processed
- Different uniqid when calld in wp_localize_script and shortcode
- Gravity forms customize field markup for the same form appearing in different places
- Gallery shortcode – change link file image size? (not using default fullsize image)
- How to force that styles are enqueued in the header?
- Edit shortcode in post content programatically
- How to change to local video player on shortcode ultimate to video.js?
- Adding shortcode field to edit gallery / Gallery Settings
- My shortcode does not call the function
- Shortcode not showing anything
- return unformatted content in encosing shortcode
- How to display Feedburner subscription count as plain text via a shortcode in post/page editor of my WordPress blog?
- Function result goes outside div
- Shortcode in my childtheme is not working
- Displaying shortcode in footer
- How to Make Archive ShortCode
- Are Shortcode Attributes Always Passed As Strings?
- Show form per shortcode
- Use another action instead of the shortcode API to display the last time a user logged in
- wp_editor not rendering the shortcode
- Default WordPress shortcodes not working?
- How to make this shortcode work for post content wordpress [duplicate]
- Pass fileurl parameter into shortcode from Advanced Custom Fields
- caption shortcode using image alt as caption
- Shortcode arguments to another shortcode
- Sanitize or treatment of string in editor via shortcode
- Is it possible to handle two or more shortcodes in a single page?
- Toggle Shortcode Sanitize Title
- Substituting value via shortcode
- Can’t render shortcode when html tag contains hyphen
- Shortcode to appear and show the date not code in Title and description of Social Media sites
- Not to escape a text
- Color on Shortcode insert that creates a button
- shortcode doesnt work on excerpt
- Adding Author URL to Nav Menu via Shortcode
- Displaying an interactive web map on my wordpress site
- how to add shortcode widget at end of main blog page
- Shortcode result appears above page content
- Pagination for custom posts loop
- Shortcode is not showing content when placed in editor (post_type = page)
- Modify [caption] shortcode so and are not used?
- May an attribute have no value?
- How to Call Related Post based on Categories Inside Post Content with Shortcode?
- SQL query to bulk change short code in all posts
- How to strip header tags & shortcodes from the_excerpt()
- shortcode display metainformation as linked image
- Multiple shortcodes only use attributes from one of the shortcodes on custom plugin
- Cannot modify class property from shortcode handler function
- Reusable Dynamic Taxonomy Shortcode
- How do i remove Business feeds Shortcode fatal error
- Can’t place endwhile in the loop properly in a shortcode
- How to reduce the image size inside an icon? [closed]
- How to insert visual compser post grid shortcode in a custom page template? [closed]
- WordPress plugin shortcodes not outputting anything
- Shortcode tags appear on mobile themes
- Manipulated shortcode output
- Where is escaped the shortcode?
- Str_replace using shortcode with multiple changes
- Changing layout of defaul gallery output to masonry
- shortcode change variable base on user
- Inserting shortcode is blanking excerpt – any ideas?
- Previous/Next with the same category
- How to remove https:// from shortcode generated url
- How to enable on custom shortcodes
- Nested ShortCode works inside the_content, but not outside of it
- Why does my shortcode query not working with search term
- How to use multiple values in “Shortcode”? [closed]