How to create [ shortcode ] in WordPress

Create Shortcode with No Parameter.

                    

<?php

function slider_code(){
return ‘Hi this message is written codelizar.’;
}

?>

Call shortcode –

                    

<?php

add_shortcode(‘slider’, ‘slider_code’);

?>

Please paste the shortcode into WordPress page / post.

[slider]

 

Create Shortcode with Parameter.

                    

<?php

function anchor_code($paras) {
extract(shortcode_atts(array(
‘targ’ => ‘_blank’,
‘title’ => ‘myanchor’,
‘val’ => ‘https://www.codelizar.com’,
‘text’=> “demo”,
), $paras));

return ‘<a href=”‘.$val.'” target=”‘.$targ.'” title=”‘.$title.'”>$text</a>’;
}

?>

Call shortcode –

                    

<?php

add_shortcode(‘anchorcode’, ‘anchor_code’);

?>

Please paste the shortcode into WordPress page / post.

[anchorcode targ=”_self” title=”wordburg” val=”https://www.youtube.com/” text=”button”]

Leave a Reply

Your email address will not be published. Required fields are marked *