How To Write WordPress Shortcode – Ins And Out

1
225
WordPress Shortcode
WordPress Shortcode

Shortcode is the great feature of WordPress. You’ll see shortcode in WordPress themes or plugins. You can make shortcode as your own way.

Open functions.php in your theme and write there below code.

At first, we’ve made a function called test_shortcode() then we’ve ‘echo’ something. Last we’ve used WordPress hook add_shortcode with callit and function name. You can use any name instead of callit.

Now if you use callit as shortcode [callit] in your post or page you’ll show output Do something!

Note: it’ll create a problem when you’ll use the shortcode beneath of a text. So use return instead of echo.

Let’s try with arguments-

Now you can use it as [callit]Show something in display[/callit] and it’ll show Show something in display on the screen.

Argument example:

You need to call the shortcode as [user name=”John” id=”1993″] it’ll show as Your name: John. Your ID: 1993 on the screen.

Show image with shortcode:

You may use the shortcode as [image height=”50px” width=”80px”]http://spoilcoconut.com/wp-content/uploads/2017/05/how-to-you-can-get-rid-ransomware-malware-696×476.jpg[/image] you’ll see the image as your preferred size.

Use code through shortcode:

You can use a lot of code in the shortcode. Just call the shortcode like [sc_show_code] really enjoyable 🙂

You can also use the shortcode in widget. But you need to add a filter in functions.php

If you like this article, then please like our Facebook Page and share it on your wall.

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here