- Navigate to the ch11-hello-world folder of the WordPress plugin directory of your development installation.
- Open the ch11-hello-world.php file in a text editor.
- Add the following line of code at the end of the file to declare a new shortcode that will be available to content authors:
add_shortcode( 'hello-world', 'ch11hw_hello_world_shortcode' );
- Add the following code section to provide an implementation for the ch11hw_hello_world_shortcode function:
function ch11hw_hello_world_shortcode() {
$options = get_option( 'ch11hw_options' );
$output = sprintf( __( 'The current text string is: %s.',
'ch11hw_hello_world' ),
$options['default_text'] );
return $output;
}
- Save and close the plugin file.
- Create a new page (using the Ajouter item of the Pages menu) and insert the new shortcode [hello-world] in the content, then publish the page (Publier).
- View the page (Voir la page) to see the output of the shortcode: