Saturday, 23 November 2019 17:06

How to Create Your Own WordPress Shortcodes

Written by 
Rate this item
(0 votes)

WordPress normally not allowing you to add Php codes  to pages and posts, It's where shortcodes comes in. when a shortcode is encountered within post text then any custom php codes can be executed.

 Php function of the shortcode can be added to any plugin 

code or in your wordpress theme’s functions.php file so 

that those php codes within the function can be run.


Following is a example of how to add shortcode function  

in functions.php file.


function doctors_shortcode( $atts ) {

    //Add any kinds of php codes here   

    //following codes just display a hello text  


    $return_data.='<div id="primary" class="site-doc-main"> Hello ';

    $return_data.='</div>'; return $return_data;


add_shortcode('DoctorShortcode', 'doctors_shortcode' );


Now Enter [DoctorShortcode] somewhere within a page or post to display the 

result of the doctors_shortcode() function.

Follow my next post about Parameterized shortcodes. 


Don't forget to like & share it. 

Connect with me if you want to learn more - , 

My professional plugin -

Read 1333 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.