< Custom WordPress Shortcode />

0
(0)

Adding a custom shortcode is easy, the code below shows you how to do it. 
Simply add this to your functions.php and add [shortcode] to your page in WordPress.

function custom_shortcode(){
	return "";
}

add_shortcode('shortcode', 'custom_shortcode'); 

Shortcode with attributes

Simply add this to your functions.php and add [shortcode attribute=POST] to your page in WordPress.

function show_list($atts = array()) {

    // set up default parameters
    extract(shortcode_atts(array(
        'request' => 'GET' // Default value = GET
    ), $atts));
    
    return "";
}
add_shortcode('shortcode', 'custom_shortcode'); 

The extract function in PHP will extract the attributes array into PHP variables. We are setting the request variable in this example with a default value, otherwise, if users will not set the attribute on the shortcode, it will give an HTTP error, because technically it is null if not set.

You can use everything, from a String to Integers and any Object. You can add as many attributes as you want.

Did this help you?

Average rating 0 / 5. Vote count: 0

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on telegram
Telegram
Share on whatsapp
WhatsApp
Share on print
Print

Did this help you?

Average rating 0 / 5. Vote count: 0

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Justin van lier

Justin van lier

I am a self taught Software Engineer with experience in managing and developing game servers, websites, applications & backend systems. I began to work on a professional level since April, 2014. I'm always excited to teach people about Computer Science and the advantages that come along.