how to write short code in word press

According to the WordPress documentation, “a minimal example of the PHP code required to create shortcode with attributes” is

// [bartag foo="foo-value"]
function bartag_func( $atts ) {
    extract( shortcode_atts( array(
        'foo' => 'something',
        'bar' => 'something else',
    ), $atts ) );

    return "foo = {$foo}";
}
add_shortcode( 'bartag', 'bartag_func' );

You can find more detailed information on creating shortcodes in the above referenced documentation.