{"id":967,"date":"2022-09-12T18:33:12","date_gmt":"2022-09-12T18:33:12","guid":{"rendered":"https:\/\/glossary.dream.press\/glossary\/%group%\/shortcode\/"},"modified":"2026-08-07T20:25:16","modified_gmt":"2026-08-07T20:25:16","slug":"shortcode","status":"publish","type":"glossary","link":"https:\/\/glossary.dream.press\/glossary\/wordpress\/shortcode\/","title":{"rendered":"Shortcode"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.dreamhost.com\/glossary\/wordpress\/wordpress\/\">WordPress<\/a> includes six built-in shortcodes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><\/code> embeds and plays audio files<\/li>\n\n\n\n<li><code><\/code> wraps captions around content, usually images<\/li>\n\n\n\n<li><code><\/code> wraps embedded items<\/li>\n\n\n\n<li><code><\/code> shows image galleries<\/li>\n\n\n\n<li><code><\/code> displays a collection of audio or video files<\/li>\n\n\n\n<li><code><\/code> embeds and plays video files<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Anything beyond those six, such as a contact form or a slideshow, comes from <a href=\"https:\/\/www.dreamhost.com\/glossary\/wordpress\/plugin\/\">plugins<\/a>. Many plugins register their own shortcodes as the way you place their output: drop the tag where the output should appear, and the plugin fills it in.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How shortcodes work<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When WordPress renders a post, it scans the content for registered bracketed tags and replaces each one with the output of the PHP function mapped to that tag. Your visitors see the gallery or the player; the tag itself never appears on the published page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The feature exists because WordPress doesn&#8217;t execute PHP placed in post content by default. The <a href=\"https:\/\/developer.wordpress.org\/plugins\/shortcodes\/\">WordPress Plugin Handbook<\/a> describes that restriction as a security precaution. Shortcodes, introduced in WordPress 2.5, let content authors trigger registered code without writing PHP themselves. The callback behind a shortcode is still PHP, though, so it&#8217;s only as safe as the developer made it: the handbook&#8217;s best practices tell shortcode developers to sanitize the input and escape the output.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Adding a shortcode to a post or page<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To add a shortcode to a <a href=\"https:\/\/www.dreamhost.com\/glossary\/wordpress\/post\/\">post<\/a> or <a href=\"https:\/\/www.dreamhost.com\/glossary\/wordpress\/page-post-type\/\">page<\/a>, open it in the <a href=\"https:\/\/www.dreamhost.com\/glossary\/wordpress\/gutenberg\/\">block editor<\/a>, click the Add Block button, and insert the Shortcode block; you&#8217;ll find it in the Widgets section of the block inserter. You can also type \/shortcode and press Enter. Then type the tag into the block.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Shortcodes are written between square brackets. For example, to add a gallery, type:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code><\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This displays the images whose attachment IDs are 1 through 6, in 3 columns, at the registered &#8216;large&#8217; image size (the default is &#8216;thumbnail&#8217;). Attachment IDs are shared with posts and pages, so your images almost never carry IDs 1 through 6. To find an image&#8217;s real ID, open it in the Media Library.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Shortcodes vs. blocks<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You&#8217;ll rarely type the built-in shortcodes by hand anymore. Since the block editor became WordPress&#8217;s default, galleries, audio, video, and embeds all have dedicated blocks. Shortcodes remain the standard way many plugins place their output.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use a block when one exists for the job. The Gallery, Audio, Video, and Embed blocks cover the same ground as the matching shortcodes and show you the result as you edit.<\/li>\n\n\n\n<li>Use a shortcode when a plugin provides one, or when you need the same dynamic output repeated across many pages.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Creating custom shortcodes<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Developers register a shortcode with the add_shortcode() function, which maps a bracketed tag to a PHP callback in a plugin or a theme&#8217;s functions.php file. Whatever the callback returns replaces the tag on the page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For more examples, including a walkthrough of building your own, see our guide <a href=\"https:\/\/www.dreamhost.com\/blog\/wordpress-shortcodes-101\/\">An Introduction to WordPress Shortcodes (With Examples)<\/a>.<\/p>\n","protected":false},"featured_media":0,"parent":0,"menu_order":0,"template":"","meta":{"_acf_changed":false,"_yoast_wpseo_focuskw":"","_yoast_wpseo_title":"What Is a Shortcode in WordPress? %%sep%% %%sitename%%","_yoast_wpseo_metadesc":"What is a shortcode? A square-bracket tag like [gallery] that WordPress swaps for dynamic content. See built-in shortcodes, syntax, and a gallery example.","_yoast_wpseo_opengraph-title":"","_yoast_wpseo_opengraph-description":"","_yoast_wpseo_twitter-title":"","_yoast_wpseo_twitter-description":""},"group":[18],"class_list":["post-967","glossary","type-glossary","status-publish","hentry","group-wordpress"],"acf":{"cta":"Managed WP Hosting","faqs":[{"question":"Why is my shortcode showing as plain text on the page?","answer":"WordPress only replaces tags that are registered. If the plugin or theme that registered a shortcode is deactivated or deleted, the raw bracketed text prints on the page for visitors; a mistyped tag fails the same way. Reactivate or replace the plugin, or delete the leftover tags."},{"question":"Can I use shortcodes in widgets or theme template files?","answer":"Yes in posts, pages, and the Text widget, which processes shortcodes automatically. Theme template files don't: a shortcode there only runs when passed through the do_shortcode() function, for example echo do_shortcode('[gallery]')."},{"question":"What happens if two plugins register the same shortcode name?","answer":"The one loaded last takes precedence. WordPress keeps one callback per shortcode tag, so when two plugins register the same name, one overrides the other. That's why WordPress tells developers to prefix shortcode names. If a shortcode's output changes unexpectedly, check for a naming collision."}],"term_definition":"A shortcode is a small tag in square brackets, like [gallery], that WordPress replaces with dynamic content when a page loads. WordPress doesn't execute PHP placed in post content by default, so shortcodes, introduced in WordPress 2.5, let you add galleries, audio, video, and plugin features by calling code a developer has already registered.","h2_more":"More About Shortcodes","title_tag":"What Is a Shortcode in WordPress?"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>What Is a Shortcode in WordPress? - DreamHost Glossary<\/title>\n<meta name=\"description\" content=\"What is a shortcode? A square-bracket tag like [gallery] that WordPress swaps for dynamic content. See built-in shortcodes, syntax, and a gallery example.\" \/>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What Is a Shortcode in WordPress? - DreamHost Glossary\" \/>\n<meta property=\"og:description\" content=\"What is a shortcode? A square-bracket tag like [gallery] that WordPress swaps for dynamic content. See built-in shortcodes, syntax, and a gallery example.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dreamhost.com\/glossary\/wordpress\/shortcode\/\" \/>\n<meta property=\"og:site_name\" content=\"DreamHost Glossary\" \/>\n<meta property=\"article:modified_time\" content=\"2026-08-07T20:25:16+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What Is a Shortcode in WordPress? - DreamHost Glossary","description":"What is a shortcode? A square-bracket tag like [gallery] that WordPress swaps for dynamic content. See built-in shortcodes, syntax, and a gallery example.","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"What Is a Shortcode in WordPress? - DreamHost Glossary","og_description":"What is a shortcode? A square-bracket tag like [gallery] that WordPress swaps for dynamic content. See built-in shortcodes, syntax, and a gallery example.","og_url":"https:\/\/www.dreamhost.com\/glossary\/wordpress\/shortcode\/","og_site_name":"DreamHost Glossary","article_modified_time":"2026-08-07T20:25:16+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/glossary.dream.press\/glossary\/wordpress\/shortcode\/","url":"https:\/\/glossary.dream.press\/glossary\/wordpress\/shortcode\/","name":"What Is a Shortcode in WordPress? - DreamHost Glossary","isPartOf":{"@id":"https:\/\/glossary.dream.press\/glossary\/#website"},"datePublished":"2022-09-12T18:33:12+00:00","dateModified":"2026-08-07T20:25:16+00:00","description":"What is a shortcode? A square-bracket tag like [gallery] that WordPress swaps for dynamic content. See built-in shortcodes, syntax, and a gallery example.","breadcrumb":{"@id":"https:\/\/glossary.dream.press\/glossary\/wordpress\/shortcode\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/glossary.dream.press\/glossary\/wordpress\/shortcode\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/glossary.dream.press\/glossary\/wordpress\/shortcode\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.dreamhost.com\/glossary\/"},{"@type":"ListItem","position":2,"name":"Terms","item":"https:\/\/www.dreamhost.com\/glossary\/%group%\/"},{"@type":"ListItem","position":3,"name":"Shortcode"}]},{"@type":"WebSite","@id":"https:\/\/glossary.dream.press\/glossary\/#website","url":"https:\/\/glossary.dream.press\/glossary\/","name":"DreamHost Glossary","description":"","publisher":{"@id":"https:\/\/glossary.dream.press\/glossary\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/glossary.dream.press\/glossary\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/glossary.dream.press\/glossary\/#organization","name":"DreamHost","url":"https:\/\/glossary.dream.press\/glossary\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/glossary.dream.press\/glossary\/#\/schema\/logo\/image\/","url":"https:\/\/glossary.dream.press\/glossary\/wp-content\/uploads\/2022\/10\/dreamhost-glossary-social.jpg","contentUrl":"https:\/\/glossary.dream.press\/glossary\/wp-content\/uploads\/2022\/10\/dreamhost-glossary-social.jpg","width":2400,"height":1256,"caption":"DreamHost"},"image":{"@id":"https:\/\/glossary.dream.press\/glossary\/#\/schema\/logo\/image\/"}}]}},"lang":"en","translations":{"en":967,"es":1697,"fr":7683,"nl":7714,"it":8685,"pt":9775,"de":9790,"pl":9805,"uk":9937,"ru":9947},"pll_sync_post":{},"_links":{"self":[{"href":"https:\/\/glossary.dream.press\/glossary\/wp-json\/wp\/v2\/glossary\/967","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/glossary.dream.press\/glossary\/wp-json\/wp\/v2\/glossary"}],"about":[{"href":"https:\/\/glossary.dream.press\/glossary\/wp-json\/wp\/v2\/types\/glossary"}],"wp:attachment":[{"href":"https:\/\/glossary.dream.press\/glossary\/wp-json\/wp\/v2\/media?parent=967"}],"wp:term":[{"taxonomy":"group","embeddable":true,"href":"https:\/\/glossary.dream.press\/glossary\/wp-json\/wp\/v2\/group?post=967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}