{"id":5826,"date":"2026-02-12T20:45:30","date_gmt":"2026-02-13T01:45:30","guid":{"rendered":"https:\/\/chubes.net\/?documentation=wordpress-shortcodes-api-hooks"},"modified":"2026-03-13T03:29:25","modified_gmt":"2026-03-13T07:29:25","slug":"wordpress-shortcodes-api-hooks","status":"publish","type":"documentation","link":"https:\/\/chubes.net\/docs\/wordpress-core\/shortcodes\/wordpress-shortcodes-api-hooks\/","title":{"rendered":"WordPress Shortcodes API Hooks"},"content":{"rendered":"<p>Filters and actions available in the WordPress Shortcodes API.<\/p><hr class=\"wp-block-separator\"\/><h2 class=\"wp-block-heading\">Filters<\/h2><h3 class=\"wp-block-heading\">pre_do_shortcode_tag<\/h3><p>Short-circuits shortcode processing before the callback is called.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">apply_filters( &#039;pre_do_shortcode_tag&#039;, false|string $output, string $tag, array $attr, array $m )<\/code><\/pre><\/div><p><strong>Parameters:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>$output<\/code> <em>(false|string)<\/em> \u2014 Return value. <code>false<\/code> to continue, or string to short-circuit.<\/li><li><code>$tag<\/code> <em>(string)<\/em> \u2014 Shortcode name<\/li><li><code>$attr<\/code> <em>(array)<\/em> \u2014 Parsed attributes (always array since 6.5.0)<\/li><li><code>$m<\/code> <em>(array)<\/em> \u2014 Full regex match array<\/li><\/ul><p><strong>Returns:<\/strong> <code>false<\/code> to process normally, or string to replace the shortcode<\/p><p><strong>Since:<\/strong> 4.7.0 (6.5.0: <code>$attr<\/code> is always array)<\/p><p><strong>Example:<\/strong><\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Cache shortcode output\nadd_filter( &#039;pre_do_shortcode_tag&#039;, function( $output, $tag, $attr, $m ) {\n    if ( &#039;expensive_shortcode&#039; !== $tag ) {\n        return false; \/\/ Not our shortcode, continue normally\n    }\n    \n    $cache_key = &#039;shortcode_&#039; . md5( serialize( $attr ) );\n    $cached = wp_cache_get( $cache_key );\n    \n    if ( false !== $cached ) {\n        return $cached; \/\/ Return cached output\n    }\n    \n    return false; \/\/ Not cached, process normally\n}, 10, 4 );<\/code><\/pre><\/div><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\">do_shortcode_tag<\/h3><p>Filters the output after a shortcode callback executes.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">apply_filters( &#039;do_shortcode_tag&#039;, string $output, string $tag, array $attr, array $m )<\/code><\/pre><\/div><p><strong>Parameters:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>$output<\/code> <em>(string)<\/em> \u2014 Shortcode output from callback<\/li><li><code>$tag<\/code> <em>(string)<\/em> \u2014 Shortcode name<\/li><li><code>$attr<\/code> <em>(array)<\/em> \u2014 Parsed attributes (always array since 6.5.0)<\/li><li><code>$m<\/code> <em>(array)<\/em> \u2014 Full regex match array<\/li><\/ul><p><strong>Returns:<\/strong> Modified output string<\/p><p><strong>Since:<\/strong> 4.7.0 (6.5.0: <code>$attr<\/code> is always array)<\/p><p><strong>Example:<\/strong><\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Wrap all shortcode output in a container\nadd_filter( &#039;do_shortcode_tag&#039;, function( $output, $tag ) {\n    return &#039;&lt;div class=&quot;shortcode-wrapper shortcode-&#039; . esc_attr( $tag ) . &#039;&quot;&gt;&#039; \n           . $output \n           . &#039;&lt;\/div&gt;&#039;;\n}, 10, 2 );<\/code><\/pre><\/div><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Cache shortcode output after processing\nadd_filter( &#039;do_shortcode_tag&#039;, function( $output, $tag, $attr ) {\n    if ( &#039;expensive_shortcode&#039; !== $tag ) {\n        return $output;\n    }\n    \n    $cache_key = &#039;shortcode_&#039; . md5( serialize( $attr ) );\n    wp_cache_set( $cache_key, $output, &#039;&#039;, HOUR_IN_SECONDS );\n    \n    return $output;\n}, 10, 3 );<\/code><\/pre><\/div><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\">shortcode_atts_{$shortcode}<\/h3><p>Filters the merged shortcode attributes for a specific shortcode.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">apply_filters( &quot;shortcode_atts_{$shortcode}&quot;, array $out, array $pairs, array $atts, string $shortcode )<\/code><\/pre><\/div><p><strong>Parameters:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>$out<\/code> <em>(array)<\/em> \u2014 Merged attributes (defaults + user values)<\/li><li><code>$pairs<\/code> <em>(array)<\/em> \u2014 Original defaults<\/li><li><code>$atts<\/code> <em>(array)<\/em> \u2014 User-provided attributes<\/li><li><code>$shortcode<\/code> <em>(string)<\/em> \u2014 Shortcode name<\/li><\/ul><p><strong>Returns:<\/strong> Modified attributes array<\/p><p><strong>Since:<\/strong> 3.6.0 (4.4.0: added <code>$shortcode<\/code> parameter)<\/p>","protected":false},"excerpt":{"rendered":"<p>Filters and actions available in the WordPress Shortcodes API. Filters pre_do_shortcode_tag Short-circuits shortcode processing before the callback is called. apply_filters( &#8216;pre_do_shortcode_tag&#8217;, false|string $output, string $tag, array $attr, array $m )&#8230;<\/p>\n","protected":false},"featured_media":0,"template":"","meta":{"footnotes":""},"tags":[],"project":[660],"project_type":[749],"class_list":["post-5826","documentation","type-documentation","status-publish","hentry","project-shortcodes","project_type-wordpress-reference"],"project_info":{"id":589,"name":"WordPress Core","slug":"wordpress-core"},"project_type_info":{"id":749,"name":"WordPress Reference","slug":"wordpress-reference"},"_links":{"self":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation\/5826","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation"}],"about":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/types\/documentation"}],"version-history":[{"count":3,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation\/5826\/revisions"}],"predecessor-version":[{"id":11001,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation\/5826\/revisions\/11001"}],"wp:attachment":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/media?parent=5826"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/tags?post=5826"},{"taxonomy":"project","embeddable":true,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/project?post=5826"},{"taxonomy":"project_type","embeddable":true,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/project_type?post=5826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}