Skip to content

Instantly share code, notes, and snippets.

@Tsunamijaan
Created January 5, 2019 09:16
Show Gist options
  • Select an option

  • Save Tsunamijaan/7ce7a8fb05816ac15b442c259ad8c44c to your computer and use it in GitHub Desktop.

Select an option

Save Tsunamijaan/7ce7a8fb05816ac15b442c259ad8c44c to your computer and use it in GitHub Desktop.
How to register shortcode in wordpress
Single shortcode======
function single_shortcode( $atts, $content = null ) {
return '<div class="singe_shortcode_wrapper">'.do_shortcode($content).'</div>';
}
add_shortcode('single_shortcode', 'single_shortcode');
=========Shortcode with attributes========
function shortcode_with_attributes( $atts, $content = null ) {
extract( shortcode_atts( array(
'attribute' => '',
'another' => ''
), $atts ) );
return '
<div class="shortcode_wrapper">
<h2>'.$attribute.'</h2>
'.$another.'
</div>
';
}
add_shortcode('shortcode_name', 'shortcode_with_attributes');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment