In WordPress, we can create our own shortcode with the help of add_shortcode() function. You have to place this shortcode function in your functions.php file.
The add_shortcode() function uses two parameters:
add_shortcode(‘shortcode’, ‘create_short_code’);
1. ‘shortcode’-> name of shortcode.
2. ‘create_short_code’-> callback function name.
The add_shortcode() function uses two parameters:
add_shortcode(‘shortcode’, ‘create_short_code’);
1. ‘shortcode’-> name of shortcode.
2. ‘create_short_code’-> callback function name.
Here’s the example for creating shortcode:
function create_short_code() {
return 'This is the test for create shortcode in wordpress';
}
add_shortcode('ShortCode', 'create_short_code');
How to use this shortcode:
1. In WordPress editor, you can call this shortcode by:
1. In WordPress editor, you can call this shortcode by:
2. In WordPress theme php files, you can call this shortcode by:
echo do_shortcode('custom_text');