skip to Main Content

I am adding my shortcodes using custom HTML block in WordPress Gutenberg editor.

[tagged_heading heading_tag="h2" description="Lorem ipsum <span data-attribute='1'></span> sodales dui."]

After updating the page all works ok, but after reloading editor window all single quotes, in data-attribute for example, changed to double quotes. How I can prevent that?

2

Answers


  1. Chosen as BEST ANSWER

    Found a fast-fix solution, which works for me. Single quotes will stay intact if they are placed on the first level and double quotes inside of the single quotes. So just swap them e.g. [tagged_heading text='Lorem ipsum dolor sit amet <mark data-tooltip="tooltip"></mark> sodales dui.']


  2. I would suggest changing your shortcode to handle something like this…

    [tagged_heading heading_tag="h2"]
      Lorem ipsum <span data-attribute="1"></span> sodales dui.
    [/tagged_heading]
    

    Your PHP code might look like:

    add_shortcode( 'tagged_heading', function( $attributes, $content, $tag ) {
        // Merge default attributes
        extract( shortcode_atts( [
            'heading_tag' => 'h1'
        ], $attributes ) );
    
        // Render.
        echo '<' . $heading_tag . '>' . $content . '</' . $heading_tag . '>';
    } );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search