How can I create a custom shortcode in my WordPress site?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our W3Make Forum to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
wp-content/themes/your-theme/functions.php
file. Inside this file, you will need to create a new PHP function. The name of this function can be anything you want, but it is a good idea to use a descriptive name that reflects the purpose of your shortcode or as you wish.add_shortcode()
function. Theadd_shortcode()
function takes two arguments: the name of the shortcode and the function that will be executed when the shortcode is used.function my_shortcode($atts) {
// This is the code that will be executed when the shortcode is used.
return 'This is my custom shortcode!';
}
add_shortcode(‘my_shortcode’, ‘my_shortcode’);
To use this shortcode, you would simply add the following code to your WordPress post or page:
[my_shortcode]
Do as directed and finally you are good to go.
To create a custom shortcode in your WordPress site, follow these steps: