{"id":1284776,"date":"2024-02-05T15:15:18","date_gmt":"2024-02-05T15:15:18","guid":{"rendered":"https:\/\/rankmath.com\/?p=1284776"},"modified":"2025-09-30T01:46:18","modified_gmt":"2025-09-30T01:46:18","slug":"how-to-add-shortcode-in-wordpress","status":"publish","type":"post","link":"https:\/\/rankmath.com\/de\/blog\/how-to-add-shortcode-in-wordpress\/","title":{"rendered":"So f\u00fcgen Sie ganz einfach einen Shortcode in WordPress hinzu"},"content":{"rendered":"<p>If you\u2019ve ever wanted to add special features or design elements to your WordPress site without touching complicated code, shortcodes are your best friend. <\/p>\n\n\n\n<p>With just a simple piece of text inside square brackets, you can insert buttons, forms, image galleries, videos, and more, anywhere on your site. <\/p>\n\n\n\n<p>The best part? <\/p>\n\n\n\n<p>You don\u2019t need to be a developer to use them. <\/p>\n\n\n\n<p>In this post, you\u2019ll learn how to easily add a shortcode in WordPress, step by step, so you can enhance your website\u2019s functionality in minutes.<\/p>\n\n\n\n<!--more-->\n\n\n\n<div id=\"toc\">\n    <h2>Inhaltsverzeichnis<\/h2>\n    <ol>\n        <li><a href=\"#understanding-shortcodes\">Understanding Shortcodes<\/a><\/li>\n        <li><a href=\"#why-use-shortcodes\">Why Use Shortcodes in WordPress?<\/a>\n        <\/li><li><a href=\"#add-a-shortcode\">Methods to Add a Shortcode in WordPress<\/a>\n            <ul>\n                <li><a href=\"#block-editor\">Add a Shortcode Using Block Editor (Gutenberg)<\/a><\/li>\n                <li><a href=\"#classic-editor\">Add a Shortcode Using the Classic Editor<\/a><\/li>\n                <li><a href=\"#widget\">Add a Shortcode Within WordPress Widget<\/a><\/li>\n                <li><a href=\"#theme-files\">Add a Shortcode Within WordPress Theme Files\u00a0<\/a><\/li>\n                \n            <\/ul>\n        <\/li>\n       <li><a href=\"#custom-shortcode\"> How to Create Your Custom Shortcode in WordPress<\/a><\/li>\n      <li><a href=\"#faq\">H\u00e4ufig gestellte Fragen<\/a><\/li>\n        <li><a href=\"#conclusion\">Fazit<\/a><\/li>\n    <\/ol>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"understanding-shortcodes\"><span class=\"number\">1<\/span>  Understanding Shortcodes<\/h2>\n\n\n\n<p>Shortcodes make it easy for you to add extra functionality to your WordPress site without touching complicated code. <\/p>\n\n\n\n<p>They\u2019re simply pieces of text placed inside square brackets. When you insert a shortcode into your post, page, or widget, WordPress automatically replaces it with the intended feature on the front end.<\/p>\n\n\n\n<p>These shortcodes are enclosed in square brackets. For instance, if you set up your <a href=\"https:\/\/rankmath.com\/blog\/local-seo\/\" data-type=\"post\" data-id=\"877362\">Local SEO using the Rank Math SEO plugin<\/a>, you&#8217;ll need to use the shortcode to display your business information, which will look like this:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#091;rank_math_contact_info]<\/code><\/pre>\n\n\n\n<p>All you need to do is paste it where you want it, and WordPress does the rest.<\/p>\n\n\n\n<p>Sometimes, you may want even more flexibility, like showing related posts, adding banner ads, or displaying image galleries. This is where the <strong>Shortcode API<\/strong> comes in. It allows developers to create custom shortcodes so you can use advanced features without needing coding knowledge.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"why-use-shortcodes\"><span class=\"number\">2<\/span>  Why Use Shortcodes in WordPress?<\/h2>\n\n\n\n<p>There are a few reasons you might want to add a shortcode to your WordPress site:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Einfach zu verwenden:<\/strong> Even if you don&#8217;t have coding experience, you can still use shortcodes to add powerful functionality to your site.<\/li>\n\n\n\n<li><strong>Versatile:<\/strong> Shortcodes are available for almost everything, from adding contact forms to displaying sliders and creating custom buttons.<\/li>\n\n\n\n<li><strong>Portable:<\/strong> If you switch themes or plugins, your shortcodes will still work if the theme or plugin that generated the shortcode remains active.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"add-a-shortcode\"><span class=\"number\">3<\/span>  Methods to Add a Shortcode in WordPress<\/h2>\n\n\n\n<p>Now, let&#8217;s discuss ways to add shortcodes to your WordPress website.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"block-editor\"><span class=\"number\">3.1<\/span>  Add a Shortcode Using Block Editor (Gutenberg)<\/h3>\n\n\n\n<p>To add a shortcode using the Block Editor, start by navigating to the <strong>Seiten<\/strong> oder <strong>Beitr\u00e4ge<\/strong> section, depending on where you want to add the shortcode.<\/p>\n\n\n\n<p>In the Block Editor, click the <strong>+<\/strong> icon, search for the <strong>Kurzwahl<\/strong> block, and add it to your page or post, as shown below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"2550\" height=\"1054\" src=\"https:\/\/rankmath.com\/wp-content\/uploads\/2024\/02\/add-shortcode-gutenberg.jpeg\" alt=\"Add a shortcode in Gutenberg\" class=\"wp-image-1284780\" \/><\/figure>\n\n\n\n<p>Once the Shortcode block is added, you&#8217;ll see a field where you can enter your shortcode. Enter the desired shortcode, including any necessary parameters within the shortcode if required.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" width=\"1942\" height=\"900\" src=\"https:\/\/rankmath.com\/wp-content\/uploads\/2024\/02\/add-your-shortcode.jpeg\" alt=\"Add your shortocde\" class=\"wp-image-1284782\" style=\"width:840px;height:auto\" \/><\/figure>\n\n\n\n<p>Once done, publish or update your page or post to make the shortcode live on your website.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"classic-editor\"><span class=\"number\">3.2<\/span>  Add a Shortcode Using the Classic Editor<\/h3>\n\n\n\n<p>To add a shortcode in the Classic editor, navigate to the <strong>Seiten<\/strong> oder <strong>Beitr\u00e4ge<\/strong> section, depending on where you want to add the shortcode. <\/p>\n\n\n\n<p>Enter the desired shortcode, including any necessary parameters within the shortcode if required.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"2534\" height=\"1026\" src=\"https:\/\/rankmath.com\/wp-content\/uploads\/2024\/02\/add-shortcode-classic-editor.jpeg\" alt=\"Add Shortcode in Classic Editor\" class=\"wp-image-1284788\" \/><\/figure>\n\n\n\n<p>Wenn Sie fertig sind, klicken Sie auf <strong>Publish\/Update <\/strong>Schaltfl\u00e4che, um Ihre \u00c4nderungen zu speichern.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"widget\"><span class=\"number\">3.3<\/span>  Add a Shortcode Within WordPress Widget<\/h3>\n\n\n\n<p>You can add a shortcode in your WordPress website&#8217;s widget areas, allowing them to appear on the sidebar, footer, or header.<\/p>\n\n\n\n<p>To begin, navigate to <strong>Appearance \u2192 Widgets<\/strong> on your WordPress dashboard. Then, locate the widget area where you wish to insert the shortcode.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1604\" height=\"628\" src=\"https:\/\/rankmath.com\/wp-content\/uploads\/2025\/09\/widget-area.jpeg\" alt=\"Navigate to Widget area\" class=\"wp-image-1609661\" \/><\/figure>\n\n\n\n<p>Next, click on the <strong>+<\/strong> icon, search for the Shortcode block, and either drag and drop it or click to place it in the desired area.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"2084\" height=\"1186\" src=\"https:\/\/rankmath.com\/wp-content\/uploads\/2024\/02\/add-shortcode-in-widget.jpeg\" alt=\"Add shortcode in Widget area\" class=\"wp-image-1284791\" \/><\/figure>\n\n\n\n<p>After adding the shortcode block, you can insert the desired shortcode within the area.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"2520\" height=\"1152\" src=\"https:\/\/rankmath.com\/wp-content\/uploads\/2024\/02\/shortocde-widget-area.jpeg\" alt=\"Add shortcode\" class=\"wp-image-1284792\" \/><\/figure>\n\n\n\n<p>Then, save the changes, and now the shortcode will be active in the widget area you selected.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"theme-files\"><span class=\"number\">3.4<\/span>  Add a Shortcode Within WordPress Theme Files&nbsp;<\/h3>\n\n\n\n<p>Shortcodes within WordPress theme files can add custom functionality to your website without relying on plugins.&nbsp;<\/p>\n\n\n\n<p>To do this, access the theme file where you intend to add a shortcode, such as page.php, single.php, or a custom template file, and use the <code>do_shortcode<\/code> function provided by WordPress.<\/p>\n\n\n\n<p>Simply pass the shortcode as a parameter to this function, and it will display the corresponding output.&nbsp;<\/p>\n\n\n\n<p>For example, if you have a shortcode called <code>[your_shortcode]<\/code>,you can add it to your theme file like this:<\/p>\n\n\n\n<p><code>&lt;?php echo do_shortcode(\"[your_shortcode]\"); ?&gt;<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"2516\" height=\"1050\" src=\"https:\/\/rankmath.com\/wp-content\/uploads\/2024\/02\/add-shortcode-code.jpeg\" alt=\"Add shortcode in theme file\" class=\"wp-image-1284798\" \/><\/figure>\n\n\n\n<p>Once you&#8217;ve added the shortcode, remember to save your changes.<\/p>\n\n\n\n<p>However, remember that your changes may get lost when the theme is updated, so it&#8217;s best to <a href=\"https:\/\/rankmath.com\/blog\/wordpress-child-theme\/\">use a child theme<\/a> when adding custom code to your theme files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"custom-shortcode\"><span class=\"number\">4<\/span>  How to Create Your Custom Shortcode in WordPress<\/h2>\n\n\n\n<p>Shortcodes are handy for adding dynamic content or custom code to WordPress posts and pages, but creating a custom shortcode requires coding skills.<\/p>\n\n\n\n<p>If you&#8217;re comfortable with PHP, use the following template code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Define a custom shortcode function\nfunction custom_shortcode() {\n    \/\/ Define the desired functionality\n    $message = 'This is my custom shortcode!';\n\n    \/\/ Return the output\n    return $message;\n}\n\n\/\/ Register the shortcode\nadd_shortcode('my_shortcode', 'custom_shortcode');<\/code><\/pre>\n\n\n\n<p>In this example, we&#8217;re creating a shortcode  <code>[my_shortcode]<\/code> that will display the text &#8220;This is my custom shortcode!&#8221; on your website.<\/p>\n\n\n\n<p>So you can add this code to your <a href=\"https:\/\/rankmath.com\/kb\/wordpress-hooks-actions-filters\/#functions-php-file\">theme\u2019s functions.php<\/a> file or use a code snippet plugin.<\/p>\n\n\n\n<p>After completing the necessary steps, you can insert the shortcode into your posts, pages, and widgets with the code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#091;my_shortcode]<\/code><\/pre>\n\n\n\n<p>When you publish or preview your post or page, the shortcode will be replaced with the output from your function.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"faq\"><span class=\"number\">5<\/span>  H\u00e4ufig gestellte Fragen<\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list\">\n<div id=\"faq-question-1707109210478\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question\">Can I use the same shortcode name in multiple functions?<\/h3>\n<div class=\"rank-math-answer\">\n\n<p>No, each shortcode must have a unique name. Using the same name for multiple shortcodes can lead to conflicts and unpredictable behavior.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1707109223354\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question\">What is the difference between shortcodes and Gutenberg blocks?<\/h3>\n<div class=\"rank-math-answer\">\n\n<p>Shortcodes are a legacy method for adding dynamic content to WordPress, utilizing a simple tag system like [my_shortcode]. Gutenberg blocks, on the other hand, are a more modern approach, offering a visual editor and a block-based structure.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1707109243009\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question\">Are shortcodes the only way to add dynamic content to WordPress?<\/h3>\n<div class=\"rank-math-answer\">\n\n<p>No, shortcodes are one method. You can also use custom post types, page templates, and action hooks to add dynamic content to your WordPress site.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\"><span class=\"number\">6<\/span>  Fazit<\/h2>\n\n\n\n<p>Shortcodes in WordPress make it easy for you to add features or elements to your site without writing code from scratch. You can insert them into posts, pages, or widgets using either the Classic Editor or the Gutenberg Editor.<\/p>\n\n\n\n<p>When using shortcodes, make sure the names are unique to avoid conflicts with other plugins or functions. <\/p>\n\n\n\n<p>Also, test your shortcodes to ensure they work correctly and remain compatible with your theme and other plugins.<\/p>\n\n\n\n<p>Wenn Ihnen dieser Beitrag gef\u00e4llt, teilen Sie uns dies bitte per E-Mail mit&nbsp;<a href=\"https:\/\/twitter.com\/rankmathseo\" target=\"_blank\" rel=\"noopener\"><strong>@rankmathseo twittern.<\/strong><\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>If you\u2019ve ever wanted to add special features or design elements to your WordPress site without touching complicated code, shortcodes are your best friend. With just a simple piece of text inside square brackets, you can insert buttons, forms, image galleries, videos, and more, anywhere on your site. The best part? You don\u2019t need to [&hellip;]<\/p>","protected":false},"author":37,"featured_media":1285073,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[136],"tags":[],"class_list":{"0":"post-1284776","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-wp-tutorials"},"_links":{"self":[{"href":"https:\/\/rankmath.com\/de\/wp-json\/wp\/v2\/posts\/1284776","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rankmath.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rankmath.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rankmath.com\/de\/wp-json\/wp\/v2\/users\/37"}],"replies":[{"embeddable":true,"href":"https:\/\/rankmath.com\/de\/wp-json\/wp\/v2\/comments?post=1284776"}],"version-history":[{"count":3,"href":"https:\/\/rankmath.com\/de\/wp-json\/wp\/v2\/posts\/1284776\/revisions"}],"predecessor-version":[{"id":1610213,"href":"https:\/\/rankmath.com\/de\/wp-json\/wp\/v2\/posts\/1284776\/revisions\/1610213"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rankmath.com\/de\/wp-json\/wp\/v2\/media\/1285073"}],"wp:attachment":[{"href":"https:\/\/rankmath.com\/de\/wp-json\/wp\/v2\/media?parent=1284776"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rankmath.com\/de\/wp-json\/wp\/v2\/categories?post=1284776"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rankmath.com\/de\/wp-json\/wp\/v2\/tags?post=1284776"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}