How to create [ shortcode ] in WordPress

Create Shortcode with No Parameter.

[dm_code_snippet background=”yes” background-mobile=”yes” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no”]

<?php

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

?>

[/dm_code_snippet]

Call shortcode –

[dm_code_snippet background=”yes” background-mobile=”yes” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no”]

<?php

add_shortcode(‘slider’, ‘slider_code’);

?>

[/dm_code_snippet]

Please paste the shortcode into WordPress page / post.

[slider]

 

Create Shortcode with Parameter.

[dm_code_snippet background=”yes” background-mobile=”yes” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no”]

<?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>’;
}

?>

[/dm_code_snippet]

Call shortcode –

[dm_code_snippet background=”yes” background-mobile=”yes” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no”]

<?php

add_shortcode(‘anchorcode’, ‘anchor_code’);

?>

[/dm_code_snippet]

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.