Could we help you? Please click the banners. We are young and desperately need the money
In this short guide, I'll show you how to make a shortcode for your WordPress.
Inside your functions.php, create a function like this:
function my_shortcode() {
ob_start();
// shortcode content
return ob_get_clean();
}
And hook it like this:
add_shortcode( 'myshortcode', 'my_shortcode' );
You can call your shortcode, inside the WordPress Text-Editor, like this:
[myshortcode]
Add a variable to your shortcode function's parameters to receive the attributes with.
function my_shortcode($atts) {
ob_start();
// shortcode content
return ob_get_clean();
}
Receive the attributes, using the shortcode_atts() function:
function my_shortcode($atts) {
$atts = shortcode_atts([
'test' => ''
], $atts);
ob_start();
// shortcode content
return ob_get_clean();
}
Each key in the array is an attribute you want to receive. The value they are set to is their fallback.