Create a shortcode in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function shortcode_function( $params ) { | |
return "Shortcode content"; | |
} | |
add_shortcode( 'shortcode_name', 'shortcode_function' ); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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