Georgi Andonov
Georgi Andonov

Reputation: 11

How to use correct nested shortcodes in wordpress

function column_left_func( $atts, $content ) {
	ob_start();
	?>
	<div class="column left">
		<?php echo $content; ?>
	</div>
	<?php
	$html = ob_get_clean();

	return $html;
}
add_shortcode('columnleft', 'column_left_func');

function column_right_func( $atts, $content ) {

	ob_start();
	?>
	<div class="column right">
		<?php echo $content; ?>
	</div>
	<?php
	$html = ob_get_clean();
	return $html;
}
add_shortcode('columnright', 'column_right_func');



function columns_func( $attr; $content ) {
	ob_start();
	?>
	<div class="content-columns">
		<?php 
		do_shortcode ( $content );
		?>
	</div>
	<?php
	$html = ob_get_clean();

	return $html;
}
add_shortcode('columns', 'columns_func');

I want to use it like [columns]

[columnleft]

Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.

[/columnleft]

[/columns]

Upvotes: 0

Views: 184

Answers (1)

Simon Pollard
Simon Pollard

Reputation: 2588

I think it should just be a small change to your first function, try...

function crb_columns_func( $atts, $content) {
    ob_start();
    ?>
    <div class="content-columns">
        <?php 
        do_shortcode ( $content );
        ?>
    </div>
    <?php
    $html = ob_get_clean();

    return $html;
}
add_shortcode('columns', 'crb_columns_func');

Upvotes: 1

Related Questions