Skip to content

Instantly share code, notes, and snippets.

@tajidyakub
Created April 24, 2018 09:56
Show Gist options
  • Save tajidyakub/014e82f8c7da50fc646bea63ffe1ef83 to your computer and use it in GitHub Desktop.
Save tajidyakub/014e82f8c7da50fc646bea63ffe1ef83 to your computer and use it in GitHub Desktop.
Contoh callback function untuk shortcode di functions.php
<?php
/**
 * Callback functiom untuk shortcode [linkbox text="" url=""]
 *
 * @param Array $atts Array yang berisi atribut shortcode
 * @return String $html String HTML yang dikembalikan ke display 
 */
function linkbox_code( $attr=[] ) {
  // Extract attribut dan masukkan ke variable
  // dengan demikian dapat diakses via $param['text'] dan $param['url']                                   
  $param = shortcode_atts( array(
                            'text' => '',
                            'url' => ''
                          ), $atts );
  // Kembalikan HTML ke display, stylenya silahkan didefinisikan terpisaj
  return '
    <div class="linkbox">
      <a href="'. $param['url'].'">'.$param['text'].'</a>
    </div>
  ';
}
// Register [linkbox]
add_shortcode('linkbox', 'linkbox_code');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment