0

I'm designing a site and I have encountered quite a big issue which I've tried to solve using shortcodes. This shortcode calls a slideshow which can have between 0-5 images.

The actual shortcode has been designed, and tested. It works absolutely fine. The issue I'm having is with the add_shortcode wordpress API. Here is the code I have at the moment.

function soc_custom_section_widget_func( $atts ) 
{
    $image_one = "";
    $image_two = "";
    $image_three = "";
    $image_four = "";
    $image_five = "";

    if(sizeof($atts) > 0)
    {
        $image_one = $atts[image_one];      
    }
    if(sizeof($atts) > 1)
    {
        $image_two = $atts[image_two];  
    }
    if(sizeof($atts) > 2)
    {
        $image_three = $atts[image_three];
    }
    if(sizeof($atts) > 3)
    {
        $image_four= $atts[image_four]; 
    }
    if(sizeof($atts) > 4)
    {
        $image_five = $atts[image_five];
    }

    $atts = shortcode_atts( array(
        'image_one' => '',
        'image_two' => '',
        'image_three' => '',
        'image_four' => '',
        'image_five' => ''
    ), $atts );

    return do_shortcode('[soc_custom_section_widget image_one='.$atts['image_one'].' image_two='.$atts['image_two'].' image_three='.$atts['image_three'].' image_four='.$atts['image_four'].' image_five='.$atts['image_five'].']');
}
add_shortcode( 'soc_custom_section_widget', 'soc_custom_section_widget_func' );

I've been attempting to solve this issue for the past couple of hours. At the moment when I refresh the page it just shows everything as blank under the header.

Thanks.

  • 1
    First, You are making a recursion, [soc_custom_section_widget] is supposed to call another shortcode? because it is calling itself rather than returning content. – Samuel Elh Nov 27 '16 at 22:43
  • Ahh. [soc_custom_section_widget] is an actual shortcode. All I want to do is output it! – Johnathan Brown Nov 27 '16 at 22:44
  • Got it. So that shortcode can take up-to 5 img and you're making a custom shortcode to use? – Samuel Elh Nov 27 '16 at 22:45
  • Exactly. Seem to be eluding me this evening. – Johnathan Brown Nov 27 '16 at 22:50
  • Can you try this pastebin.com/C97574FC and now use [soc_custom_section_widget_custom]? – Samuel Elh Nov 27 '16 at 22:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.