//slider shortcode
function slider_shortcode($atts) {
extract( shortcode_atts( array(
'id' => ''), $atts));
$id = $id;
ob_start();?>
<div class="gallary">
<?php
// Check rows exists.
if( have_rows('slider',$id) ):
// Loop through rows.
while( have_rows('slider',$id) ) : the_row();
$slider_image = get_sub_field('slider_image');
$slider_heading = get_sub_field('slider_heading');
$slider_text = get_sub_field('slider_text');
$slider_button = get_sub_field('slider_button');
$slider_button_link = get_sub_field('slider_button_link');?>
<div>
<div class="display">
<div class="text">
<h3><?php echo $slider_heading; ?></h1>
<p><?php echo $slider_text; ?></p>
<a class="shop_now" href="<?php echo $slider_button_link;?>" class="btn_slide"><?php echo $slider_button; ?></a>
</div>
<div class="image">
<img class="p_image" src="<?php echo $slider_image; ?>"/>
</div>
</div>
</div>
<?php
// End loop.
endwhile;
// No value.
else :
endif;
?>
</div>
<?php
}
add_shortcode('carousel', 'slider_shortcode');
//js
jQuery(document).ready(function($){
jQuery(".gallary").slick({
dots:true,
autoplay: true,
fade: true,
autoplaySpeed: 3000,
});
});
page links:/
I think this error occur because of ob_get_clean() but when i add at last the whole slider gone hide any kind of help thanks in advance :)
//slider shortcode
function slider_shortcode($atts) {
extract( shortcode_atts( array(
'id' => ''), $atts));
$id = $id;
ob_start();?>
<div class="gallary">
<?php
// Check rows exists.
if( have_rows('slider',$id) ):
// Loop through rows.
while( have_rows('slider',$id) ) : the_row();
$slider_image = get_sub_field('slider_image');
$slider_heading = get_sub_field('slider_heading');
$slider_text = get_sub_field('slider_text');
$slider_button = get_sub_field('slider_button');
$slider_button_link = get_sub_field('slider_button_link');?>
<div>
<div class="display">
<div class="text">
<h3><?php echo $slider_heading; ?></h1>
<p><?php echo $slider_text; ?></p>
<a class="shop_now" href="<?php echo $slider_button_link;?>" class="btn_slide"><?php echo $slider_button; ?></a>
</div>
<div class="image">
<img class="p_image" src="<?php echo $slider_image; ?>"/>
</div>
</div>
</div>
<?php
// End loop.
endwhile;
// No value.
else :
endif;
?>
</div>
<?php
}
add_shortcode('carousel', 'slider_shortcode');
//js
jQuery(document).ready(function($){
jQuery(".gallary").slick({
dots:true,
autoplay: true,
fade: true,
autoplaySpeed: 3000,
});
});
page links:https://theelectronicstore.in/demo/
I think this error occur because of ob_get_clean() but when i add at last the whole slider gone hide any kind of help thanks in advance :)
Share Improve this question edited Mar 8, 2022 at 14:59 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Feb 10, 2022 at 8:21 MR. shaikh__92MR. shaikh__92 257 bronze badges1 Answer
Reset to default 0You need to return the value from the output buffer, like this:
//slider shortcode
function slider_shortcode($atts) {
extract( shortcode_atts( array(
'id' => ''), $atts));
$id = $id;
ob_start();?>
<div class="gallary">
<?php
// Check rows exists.
if( have_rows('slider',$id) ):
// Loop through rows.
while( have_rows('slider',$id) ) : the_row();
$slider_image = get_sub_field('slider_image');
$slider_heading = get_sub_field('slider_heading');
$slider_text = get_sub_field('slider_text');
$slider_button = get_sub_field('slider_button');
$slider_button_link = get_sub_field('slider_button_link');?>
<div>
<div class="display">
<div class="text">
<h3><?php echo $slider_heading; ?></h1>
<p><?php echo $slider_text; ?></p>
<a class="shop_now" href="<?php echo $slider_button_link;?>" class="btn_slide"><?php echo $slider_button; ?></a>
</div>
<div class="image">
<img class="p_image" src="<?php echo $slider_image; ?>"/>
</div>
</div>
</div>
<?php
// End loop.
endwhile;
// No value.
else :
endif;
?>
</div>
<?php
$output_string = ob_get_contents();
ob_end_clean();
return $output_string;
}
add_shortcode('carousel', 'slider_shortcode');
I've added those lines to the very end of your function:
$output_string = ob_get_contents();
ob_end_clean();
return $output_string;