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.