WordPress Shortcode Generator

Build your own shortcode in a minute: pick its name, attributes and defaults, write an HTML template, and get safe add_shortcode code to paste or a small plugin file, with a usage example and a live preview.

Create the shortcode

Generator

When should you use a shortcode?

Repeated content

A notice box, order button or price card you place on dozens of pages and edit in one place.

Site data

Post counts, latest products or the user’s name inside page text.

Any editor

Works in the classic editor, the block editor and the Elementor Shortcode widget.

Security in the generated code

Where in the templateFunctionWhy
Plain textesc_htmlStops tags or scripts coming in from an attribute
Inside a tag, like style or classesc_attrStops quotes breaking out
Attributes named url, link or srcesc_urlAllows valid links only
{content}wp_kses_postAllows normal post tags only

So you never sanitise values yourself. For other ready site code, try WordPress snippets.

Functions you will use with shortcodes

add_shortcodeadd_shortcode( 'my_box', 'fn' )
shortcode_attsshortcode_atts( $defaults, $atts, 'my_box' )
do_shortcodeecho do_shortcode( '[my_box]' );
In a template

Put the code in a file in wp-content/mu-plugins, not the theme, so your shortcodes do not turn into visible text if you switch themes.

Example: one “Order now” button everywhere

Create an [order_btn] shortcode with text and url attributes and place it on every service page. When the order link or button colour changes, you edit one file instead of every page.

Key terms

Short definitions of what you meet along the way.

Shortcode
A code in square brackets that WordPress replaces with content when the page is shown.
Attributes
Options written inside the shortcode, like title="…", to change what shows.
Escaping
Cleaning values before printing them so no tags or scripts get injected.

Frequently asked questions

Did not find your answer? Ask us on WhatsApp

Where do I put the code?

Best as a file in wp-content/mu-plugins that works with any theme, or at the end of a child theme functions.php.

The shortcode shows as bracketed text. Why?

The code is not loaded: check the file is in the right folder and the name on the page matches the shortcode exactly.

Can I use it in Elementor?

Yes, with the Shortcode widget or inside the text editor.

Does it slow the site?

No, a shortcode is a small PHP function. What can slow it is what you put inside, like heavy queries.

A fast WordPress site without the headache?

WordPress-tuned hosting with one-click install, backups and Arabic support.

'; O.innerHTML='

'+T('طريقة الاستخدام','How to use it')+'

'+T('في أي صفحة أو مقالة','In any page or post')+'
'+H.esc(use)+'
'+ '

'+T('الكود','The code')+'

'+(mu?'wp-content/mu-plugins/shortcode-'+tag+'.php':'functions.php')+''+(mu?' ':'')+'
'+H.esc(c)+'
'+ (unknown.length?'

'+T('في القالب متغيرات غير معرّفة في الخصائص، وستظهر كما هي: ','The template has placeholders that are not attributes and will show as typed: ')+H.esc(unknown.map(function(x){return '{'+x+'}'}).join(' '))+'

':'')+ '

'+T('المعاينة بالقيم الافتراضية','Preview with the default values')+'

'; O.querySelector('.hyt-scpv').srcdoc=doc; var d=document.getElementById('hyt-dl');if(d)d.onclick=function(){dl('shortcode-'+tag+'.php',c)}} G.addEventListener('input',build);G.addEventListener('change',build);G.addEventListener('submit',function(e){e.preventDefault();build()});build(); })();
Contact us on WhatsApp