Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress shortcode with multiline parameters

How to insert shortcode with more parameters and multiline into WordPress page? Backslash used to work as a line separator:

[my_shorcode parameter_1=10 \
   parameter_2=20 \
   parameter_3="test"]

But it doesn't work in the latest WordPress version. I want to use more lines for better readability of the code.

like image 896
Pavel Madr Avatar asked Feb 12 '20 14:02

Pavel Madr


1 Answers

Thanks for @Arvind K. for advice

This is not good idea since it breaks normal post editing behavior. Rather you should try to keep shortcodes "short

I've been solving this problem by the way

1. I have used shortcode this way [my-shortcode id="1"]

2. I have created post type My Shortcodes

3. The id for step 1. is the My Shortcodes post id

4. In ACF (Custom fields) I have created fields for My Shortcodes

(Field - is shortcode param)

5. Then you could use your My Shortcodes post for getting fields.

add_shortcode( 'my-shortcode', function ( $atts, $content ) {    
    $custom_shortcode_id = $atts['id'];

    $parameter_1 = get_field( 'parameter_1', $custom_shortcode_id );
    $parameter_2 = get_field( 'parameter_2', $custom_shortcode_id );

    return "Your shortcode content $parameter_1, $parameter_2";
} );
like image 98
Andrii Kovalenko Avatar answered Oct 23 '22 04:10

Andrii Kovalenko