If you look at the source code of add_shortcode
you will see this function doing little more than store the name of the shortcode in a global array. So, checking if a shortcode exists means looking it up in the array.
Hence, if you want to check for a specific shortcode in the_content
you must be sure that shortcode has already been added at the point you need it. Else has_shortcode
will say it doesn’t exist.
Luckily, looking at the hook order, you see template_redirect
being executed after after_setup_theme
, the default hook to load theme related stuff. If you use that hook to add your shortcode (in functions.php
), you can be sure your shortcode exists by the time you get to template_redirect
.
So, yes, you are on the right track. You’re using the right hook and the data you need is available at that point in WP’s execution order.
Related Posts:
- Redirect function inside a Shortcode
- Login form from shortcode doesn’t redirect after successful login
- Set redirect for need login
- Which method to use when deleting posts from the front-end
- Add an access code form to call a unique page based on page without registration
- Using get_option() in JavaScript
- Shortcode empty attribute
- Using wp_editor in shortcode
- Making a Shortcode [NEXT] and [PREVIOUS] to place into specific posts for post navigation
- How to display the site name in a WordPress page, or post
- How can I put a wp_redirect into a shortcode?
- Native “playlist” shortcode random playing… How?
- Using audio shortcode for .mp3 URLs with a query string
- Get multiple shortcode attribute values
- Why do_shortcode is not executing the shortcode in data-* html attributes?
- How to display some selected user meta data on a specific page with a shortcode?
- Is shortcode_unautop() broken?
- Some doubts about gallery shortcode in WordPress
- has_shortcode for content added after the content
- Shortcode displays only default attribute values
- Creating a Slider Shortcode Based on Nivo Slider
- How can I make a shortcode from this code?
- Meta tags in shortcode
- Adding PHP/HTML code inside page from custom template
- WordPress auto adds p to shortcode parameters
- Why isn’t this youtube shortcode working?
- Gist shortcode is not working
- ShortCode and extra
- How to change page title (from a plugin) in twentytwentyone theme
- WordPress Code Standards and Working $link Parameters In Shortcode
- How to set Contact Form 7 fields default value using shortcode attribute? [closed]
- Display post metadata: “title, category, author, date” with shortcode
- shortcode get thumbnail size
- Shortcodes Keep Wrapping in
- Check if post has gallery images/media
- If you add a shortcode programmatically, but the code isn’t viewed on that request, is it still executed?
- Problem with using custom shortcode with ACF WYSIWYG field
- Add shortcode support to custom field
- Shortcode help: If no image entered take default
- How can I escape a section of my page which contains multiple shortcodes?
- Populate shortcodes with table data and get next row
- Running shortcode with variable that is modified
- shortcode to display post by category entered by user without plugin
- How to apply an ID to Shortcode Embedded iframe
- How to change the output of gallery shortcode
- wp_list_pages shortcode jumps above previous content
- Shortcode attributes don’t appear?
- Shortcodes: closing shortcode not being processed
- Using $this from child class inside shortcode function
- Div-Wrap with Functions.php in Childtheme using Shortcode!
- Trying to call dynamic content as a shortcode attribute
- How to trace shortcode to its functionality
- shortcode issue in the_excerpt
- If else with shortcodes
- Using shortcodes to communicate my page design
- How to check if a post has any one of many shortcodes?
- WordPress 302 Redirect to Random Product/Post/Page
- Custom Shortcode + Querying and Ordering Posts using multiple Advanced Custom checkboxes
- Add div on EMED Tag
- call other shortcode in the email contactform7 send [closed]
- Putting a space between the buttons [closed]
- Processing a login/register form before shortcodes are rendered?
- Insert First Image into post (full-width)
- Dynamic number within shortcode
- How can i strip shortcode from HTML title tag?
- Returning HTML to Shortcode Block
- WP REST API remove the WordPress shortcodes from the JSON wp/v2/posts content->rendered
- How to display html element and php string in the same line?
- How do I share a site only to one User at the time? Please help π₯Ίπ
- Hide download option video shortcode
- WordPress Shorcode Display hierarchical taxonomy [child, parent]
- Shortcode not working in Jetpack Top Posts & Pages widget
- Restricting shortcode for users
- Gutenberg running code only available in front end within shortcode
- Insert HTML in content property and render it using shortcodes
- Redirect per shortcode if user is logged in
- Shortcode, vs blocks, vs templates – what would you do for choosing or creating custom post data in editor?
- create shortcode that changes url endpoint
- Convert WordPress shortcodes into plain html
- Attributes are not passed on nested shortcode
- Second attribute of shortcode is not changing why?
- How to make a shortcode with a line break in it parse correctly?
- Removing text + shortcode from all posts
- Plugin Shortcode value in post
- Woocommerce Filter Main Loop by Tag [closed]
- Shortcodes: override a shortcode / change shortcode on the fly
- Access the resized images generated by `add_image_size()`
- Separating Custom Template logic
- Defining the output of a WordPress Att
- Custom WP theme not showing shortcodes
- woocommerce Product shortcode create [closed]
- A number appears inside a div called wpb_wrapper, when I use a custom shortcode
- Enclose article’s body with default shortcode
- Why is my ajax live search not working when i use a shortcode to call it?
- Shortcode with foreach
- WordPress functions.php shortcode is not working [closed]
- My first WordPress shortcode just returning []
- WordPress shortcode select option not working [closed]
- How to reuse php templates as shortcodes?
- Shortcode attributes from meta query variables