1function create_shortcode(){
2 return "<h2>Hello world !</h2>";
3}
4add_shortcode('my_shortcode', 'create_shortcode');
5// Use [my_shortcode]
1function wpdocs_bartag_func( $atts ) {
2 $atts = shortcode_atts(
3 array(
4 'foo' => 'no foo',
5 'bar' => 'default bar',
6 ), $atts, 'bartag' );
7
8 return 'bartag: ' . esc_html( $atts['foo'] ) . ' ' . esc_html( $atts['bar'] );
9}
10add_shortcode( 'bartag', 'wpdocs_bartag_func' );
1function wp_demo_shortcode() {
2
3//Turn on output buffering
4ob_start();
5$code = 'Hello World';
6ob_get_clean();
7
8 // Output needs to be return
9return $code;
10}
11
12// register shortcode
13add_shortcode('helloworld', 'wp_demo_shortcode');
1// function that runs when shortcode is called
2function wpb_demo_shortcode() {
3
4// Things that you want to do.
5$message = 'Hello world!';
6
7// Output needs to be return
8return $message;
9}
10// register shortcode
11add_shortcode('greeting', 'wpb_demo_shortcode');
12