admin管理员组文章数量:1296292
I am having a problem where my markup is rendered incorrectly (more space because of <br />
) as WordPress adds <br />
everywhere theres a line break
eg.
[x]
[y]Hello world[/y]
[y]A test[/y]
[/x]
In the handler for x
the $content
looks like
<br />
[y]Hello world[/y]
<br />
[y]A test[/y]
<br />
Am I suppose to strip out all the line breaks?
UPDATE
I notice that no line breaks
[x][y]Photoshop[/y][y]Notepad++[/y][/x]
[y]Notepad++[/y]
will not be rendered as a shortcode. I must have a space like
[x][y]Photoshop[/y] [y]Notepad++[/y][/x]
^
Isit?
I am having a problem where my markup is rendered incorrectly (more space because of <br />
) as WordPress adds <br />
everywhere theres a line break
eg.
[x]
[y]Hello world[/y]
[y]A test[/y]
[/x]
In the handler for x
the $content
looks like
<br />
[y]Hello world[/y]
<br />
[y]A test[/y]
<br />
Am I suppose to strip out all the line breaks?
UPDATE
I notice that no line breaks
[x][y]Photoshop[/y][y]Notepad++[/y][/x]
[y]Notepad++[/y]
will not be rendered as a shortcode. I must have a space like
[x][y]Photoshop[/y] [y]Notepad++[/y][/x]
^
Isit?
Share Improve this question asked Apr 18, 2011 at 7:36 JM at WorkJM at Work 2,3236 gold badges35 silver badges42 bronze badges 2 |5 Answers
Reset to default 1before you register your shortcode, add the filter to the content for unautop:
add_filter( 'the_content', 'shortcode_unautop' );
Do this also for the areas, maybe excerpt or widget, when your shortcode add to this areas.
When you are in the post editor, press CTRL + ENTER
when you go to a new line. Doing that tells WordPress not to add a <br />
tag in your code.
I couldn't get the above solutions to work, so I did a CSS hack to hide the
tags:
.my-custom-shortcode br {
display: none;
}
There shouldn't be any br tags by default ! but if you are getting any in your content without even using them try adding esc_attr or esc_html before returning the variables that holds the values of your shortcode
The solution is given by this post.
You have to change the priority of the filter which adds line breaks:
remove_filter('the_content', 'wpautop');
add_filter('the_content', 'wpautop', 100);
本文标签: editorWordPress adds br in between my shortcode
版权声明:本文标题:editor - WordPress adds br in between my shortcode 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741628729a2389231.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
the_content
or using an actual registered shortcode? – t31os Commented Apr 18, 2011 at 11:27add_shortcode()
– JM at Work Commented Apr 19, 2011 at 1:33