Used shorcodes can be retrived only if they are added in post content (or any content saved in db). They can not be retrived if hardcoded in template files (TBH, they can, but that’s not the issue here). This code can help you to get the shortcodes used in a post content.
function wpse387291_get_shortcodes() {
global $post;
$pattern = get_shortcode_regex();
if ( preg_match_all( "https://wordpress.stackexchange.com/". $pattern .'/s', $post->post_content, $matches ) {
//$matches will hold the shortcodes if any
echo '<pre>' . print_r( $matches, true ) . '</pre>';
}
}
add_action( 'wp', 'wpse387291_get_shortcodes' );
You can use any hook that runs after wp
.
Related Posts:
- Using action hooks inside of a shortcode
- Enclosing Shortcode Within Another Enclosing Shortcode Breaks Output Functionality
- Which method to use when deleting posts from the front-end
- Why are you using add_action for shortcode?
- Enqueue style inside shortcode but its loaded at the bottom of page (before footer scripts)
- Pros and cons of actions over shortcodes
- manipulate a plugins shortcode
- Print shortcode in custom action hook not where the shortcode is entered
- Remove and restore one shortcode
- passing parameters to do action from shortcode to wp_footer
- Convert HTML Script to Shortcode [closed]
- Use another action instead of the shortcode API to display the last time a user logged in
- Modifying the wordpress login page and then referencing it with a shortcode problem
- contact form 7 :create shortcode usable in email message [closed]
- How to create shortcode for auto login after registration
- Hook into existing shortcodes to manipulate the attributes?
- Using wp_editor in shortcode
- How to get URL param to shortcode?
- Perform action on WPMU blog deletion
- How to display the names of users from a specific group with a shortcode?
- How do I Make a Theme “plugin-ready”?
- shortcode for logo image
- Stop strip_shortcodes() stripping content inside shortcodes
- How do i link gallery thumbnails to different url’s using the wp native gallery?
- How to display some selected user meta data on a specific page with a shortcode?
- Is it possible to create an action hook using do_action() within add_action()?
- An action hook where a comment meta is updated
- How to Remove a Filter from the Admin List Table?
- Gallery shortcode menu order fix no longer working on WordPress 4.0
- How to save a shortcode in a Gutenberg custom block?
- Shortcode displays only default attribute values
- Too many actions/filters!
- Can a shortcode function this way
- Dynamically create shortcodes using add_shortcode and a callback
- Passing attributes to shortcode dynamically
- Stop parsing shortcodes
- How can I hook into creating a new post and execute wp_die(), before the post is inserted into the database?
- Gist shortcode is not working
- Display post metadata: “title, category, author, date” with shortcode
- shortcode javascript not working on custom template file inside theme folder
- Check if post has gallery images/media
- Stop auto formatting in shortcodes
- Get URL Param Plugin and Inserting Result in Widget Code
- Add shortcode support to custom field
- Preserve shortcode content formatting
- Shortcode help: If no image entered take default
- Reloading a Mediaelement audio player
- Shortcode is not processed when added to option field using wp_editor
- Adding Shortcode Values to wp_head
- Filter Posts from the Main Query
- Copy post to separate database with “add_action(….)”
- Shortcodes: closing shortcode not being processed
- Retrieving post excerpt as a shortcode
- Bug: Post needs to be updated twice when adding action for save_post hook
- How can I override one post and make it display content for another post?
- Insert PHP code via shortcode?
- Trying to call dynamic content as a shortcode attribute
- What is the correct syntax to append a URL using a shortcode for an iframe?
- Shortcodes in RSS excerpts
- How to add shortcode to html widget
- Implementing a URL Shortener
- WordPress User ID as Shortcode
- dynamic add_action according to child pages (for homepage control)
- Remove action in a parent theme from the child theme
- Remove action within a class in a parent theme’s includes folder from the child theme
- Send an e-mail notification to custom user role when a file is uploaded to uploads folder
- Add div on EMED Tag
- Clean way of using ob_start() and ob_end_clean() in wordpress
- Theme Convert PHP code to shortcode
- find shortcode inside content of post
- WordPress Short code for List style
- Processing a login/register form before shortcodes are rendered?
- Adding a cover image to video shortcode
- Display taxonomy with a maximum number of letters
- Insert First Image into post (full-width)
- Show content if user left comment / non-logged visitors?
- How to insert current user ID/entry ID into a shortcode?
- Using `set_transient()` when saving a custom post type
- Need help with creating a simple shortcode
- Using a WP shortcode in Homepage
- i want to show a modal when user lands on home page very first time
- Save_post – Warning: Cannot modify header information
- create shortcode that changes url endpoint
- How do I remove an action hook inside a class that is called by another class?
- Logout user if click on a custom page link
- Shortcode Attribute not defined
- Add two or multiple functions in WordPress Post or Page
- Removing text + shortcode from all posts
- Is Post-Author-Id shortocde
- Load next post by ID on a single page
- Add catagory attribute to custom shortcode
- Class variables in shortcodes
- Defining the output of a WordPress Att
- Remove width and height attributes from [gallery] output
- Custom WP theme not showing shortcodes
- Shortcode for sectors
- How to not show shortcode contents if cart is empty?
- How wordpress plugin hooks works? [duplicate]
- Help with Shortcode Functionality
- How do write this type shortcode? [closed]