Lots of Googling has still not yielded a solution. Here is the problem:
I have created a custom Wordpress shortcode to use inside my Thesis theme. The goal of the shortcode is to allow users to wrap content on a page/post in Schema markup tags. My code is below:
function articlesection_rs_shortcode($atts, $content) {
$content = do_shortcode($content);
return '<span itemprop="articleSection">'.wpautop($content).'</span>';
}
add_shortcode('schema_article_section', 'articlesection_rs_shortcode');
But here is the issue. If the content between my shortcode opening/closing tags has no HTML elements, everything looks good. If, however, I have any HTML tags on inner content, the closing </span>
gets placed at the very end of my content, instead of where I placed the closing shortcode tag. Visual example:
Output when content inside shortcode is plain-text:
<span itemprop="articleSection">test content</span>
Output when content inside shortcode is HTML content:
<span itemprop="articleSection">
<h1>test content</h1>
.........
<!-- More Content Until end of page -->
</span>
I have tried using wpautop()
and wptexturize()
but no luck.
I am using Wordpress 3.8.2 and Thesis 1.8.5. Any help, advice, code, or links are much appreciated.
EDIT: Anyone have any ideas?
Lots of Googling has still not yielded a solution. Here is the problem:
I have created a custom Wordpress shortcode to use inside my Thesis theme. The goal of the shortcode is to allow users to wrap content on a page/post in Schema markup tags. My code is below:
function articlesection_rs_shortcode($atts, $content) {
$content = do_shortcode($content);
return '<span itemprop="articleSection">'.wpautop($content).'</span>';
}
add_shortcode('schema_article_section', 'articlesection_rs_shortcode');
But here is the issue. If the content between my shortcode opening/closing tags has no HTML elements, everything looks good. If, however, I have any HTML tags on inner content, the closing </span>
gets placed at the very end of my content, instead of where I placed the closing shortcode tag. Visual example:
Output when content inside shortcode is plain-text:
<span itemprop="articleSection">test content</span>
Output when content inside shortcode is HTML content:
<span itemprop="articleSection">
<h1>test content</h1>
.........
<!-- More Content Until end of page -->
</span>
I have tried using wpautop()
and wptexturize()
but no luck.
I am using Wordpress 3.8.2 and Thesis 1.8.5. Any help, advice, code, or links are much appreciated.
EDIT: Anyone have any ideas?
Share Improve this question edited Apr 14, 2014 at 19:38 Kirill M asked Apr 11, 2014 at 20:46 Kirill MKirill M 111 silver badge4 bronze badges 4 |3 Answers
Reset to default 1There was some weird issue with how Wordpress was handling line-breaks and auto styling between the shortcodes. After some more playing around was able to eliminate the issue. Very finicky system...
Here you go. I think the first problem was calling do_shortcode($content)
that gets called by add_shortcode()
so it's redundant here. Then I think calling wpautop($content)
introduced another problem rather than getting closer to a solution.
function articlesection_rs_shortcode($atts, $content) {
return '<span itemprop="articleSection">'. $content .'</span>';
}
add_shortcode('schema_article_section', 'articlesection_rs_shortcode');
Try this:
function shortcode_func( $atts ) {
ob_start();
echo 'shortcode output';
$output = ob_get_contents();
ob_end_clean();
echo $output; // Here comes the total output of your shortcode
}
add_shortcode( 'shortcode', 'shortcode_func' );
<h1>test content</h1>
enough? – Rarst Commented Apr 11, 2014 at 20:50