plugin development – How to Pass ID through Short Code

Question

You can get the ID by extracting the shortcode attributes. Check out the example below:

function shortcode_function($atts) {
    extract(shortcode_atts(array('id' => ''), $atts));
    return $id;
}
add_shortcode('my-shortcode', 'shortcode_function');

In this example you set a fallback ID of empty string. You can also set it to false if you want. In the array within shortcode_atts you can define multiple attributes and handle them as you please.

0
Foysal 5 months 2022-07-18T09:09:55-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse