Shortcode

In this lecture, we are going to create our own shortcode. If you’re not sure what shortcodes are? Basically, a little snippet that you can put into the content editor that will run a piece of code and people see the result on the front page. we will create a function and route the shortcode with the help of wordpress pre-build hook.

Simple Shortcode
Now it’s time to create our first simple shortcode, copy the below code, and paste it into functions.php file and it returns “Hello Word”. ane we create this shortcode method with the help of add_shortcode method. add this to  [my_first_shortcode]  in content editor.

function my_shortcode(){

    return 'Hello World';

}
add_shortcode('my_first_shortcode','my_shortcode');

 

Shortcode Funtion

The above code is to create a shortcode, and we return a string value in it. We also return methods and template parts just like below.

function my_shortcode(){

    return get_template_part( 'template/latest','blogs' );

}
add_shortcode('my_first_shortcode','my_shortcode');

 

#BeingCodeStuffer

Related Theme Developments