Skip to content

Instantly share code, notes, and snippets.

@hlashbrooke
Created October 16, 2014 12:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hlashbrooke/34d9c6a9af55161421cb to your computer and use it in GitHub Desktop.
Save hlashbrooke/34d9c6a9af55161421cb to your computer and use it in GitHub Desktop.
Create a shortcode in WordPress
<?php
function shortcode_function( $params ) {
return "Shortcode content";
}
add_shortcode( 'shortcode_name', 'shortcode_function' );
?>
<?php
function shortcode_function( $params ) {
//Extract parameters and supply default values
extract( shortcode_atts( array(
'param1' => 'this',
'param2' => 'that',
), $params ) );
//The parameters are now stored as variables
return "First parameter = " . $param1 . " | Second parameter = " . $param2;
}
add_shortcode( 'shortcode_name', 'shortcode_function' );
?>
<?php
function shortcode_function( $params, $content = null ) {
return "<div id='shortcode_content'>" . $content . "</div>";
}
add_shortcode( 'shortcode_name', 'shortcode_function' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment