Shortcode is a special feature of wordpress . In other words we can call it a simple set of functions Developer can create the functionality specific shortcode and can use it either at admin end in page or post or in any code file.
The following short code is used to display a simple message .
How to create and use Shortcode:
1) Create Shortcode in functions.php file
function get_message() {
return "Welcome User, This is the proper way how to declare and use a shortcode";
}
add_shortcode('call_shortcode', 'get_message');
2) Now add the following code where you want to display the message.
A) For adding "Admin" post or page.
[call_shortcode]
B) Using short code in any file of project.
echo do_shortcode('[call_shortcode]');
We can also pass parameters while calling shortcode
[call_shortcode name="test"]
function get_message($atts, $content = null) {
extract( shortcode_atts( array(
'name' => ''
), $atts ) );
return "Welcome ".$name;
}
0 Comment(s)