Custom shortcodes WordPress

First create the shortcode in the backend

function custom_avatar_function() {
return '<img src="https://blog.sergiobasic.com/wp-content/uploads/2021/04/Asset-1.png" 
    alt="doti-avatar" width="96" height="96" class="left-align" />';
}
add_shortcode('custom_avatar_function_avatar', 'custom_avatar_function_avatar_function');
function custom_avatar_function_rating_function( $atts = array() ) {
    // set up default parameters 
    extract( shortcode_atts( array(
        'stars' => '5',
    ), $atts ));
   return '<img src="https://blog.sergiobasic.com/wp-content/uploads/2021/04/Asset-1.png"
      alt="custom-avatar" width="96" height="96" class="left-align" />';
}
add_shortcode('custom_avatar_function_rating', 'custom_avatar_function_rating_function'); }

Using the first argument from the code as the shortcode

[custom_avatar_function_avatar]
[custom_avatar_function_rating stars=1]

 


// function custom_code_ca( $atts = array() ) {
// 	$tmp = shortcode_atts( array(
// 		'text' => 'hello'
// 	), $atts);
// 	return "Hellow ".$tmp['text']." .";
// }

// add_shortcode('custom_code_ca_output', 'custom_code_ca');






// function custom_code_ca( $atts = array() ) {
// 	$tmp = shortcode_atts( array(
// 		'text' => 'hello'
// 	), $atts);
// 	return "Hellow ".$tmp['text']." .";
// }

// add_shortcode('custom_code_ca_output', 'custom_code_ca');


// function torque_hello_world_shortcode( $atts ) {
//    $a = shortcode_atts( array(
//       'name' => 'world'
//    ), $atts );
//    return 'Hello ' . $a['name'] . !';
// }

// add_shortcode( 'helloworld', 'torque_hello_world_shortcode' );

 

More info here , wpbeginner

Was this article helpful?

Related Articles

Leave A Comment?