Divi WordPress Theme
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix fixing invalid argument supplied for foreach() problem

Discussion in 'Misc WordPress Requests' started by jordmiguel, Nov 2, 2017.

  1. jordmiguel


    fixing invalid argument supplied for foreach() problem, by jordmiguel

    I’ve noticed that the div image-16-8 from my hero.php file is not being displayed.

    When I inspect element I get Invalid argument supplied for foreach() in

    Here is the code:


    function tbhHeroShortcode($atts)

    $values = shortcode_atts(array(
    'images' => '',
    'first-line' => '',
    'second-line' => '',
    'video' => '',
    'link' => '',
    ), $atts);
    <div class="hero">
    $images = decode_shortcode_data($values['images']);
    if ($images): ?>
    <ul data-simple-slider>
    <?php foreach ($images as $image): ?>
    <div class="image-16-8" style="background-image: url(<?= $image->url; ?>); "></div>
    <?php endforeach; ?>
    <?php endif; ?>
    <div class="hero-content">
    <div class="hero-content-first-line">
    <h1 class="header"><?= decode_shortcode_data($values['first-line']) ?></h1>

    <h1 class="italic-header"><?= decode_shortcode_data($values['second-line']) ?></h1>

    <div class="hero-content-cta">
    <a class="hollow-button" href="<?= decode_shortcode_data($values['link']) ?>">Learn More</a>



    <?php if (count($images) > 1): ?>
    <div class="hero-controls">
    <i class="fa fa-chevron-left hero-controls__left" aria-hidden="true"></i>
    <i class="fa fa-chevron-right hero-controls__right" aria-hidden="true"></i>
    <?php endif; ?>
    $component = ob_get_contents();
    return $component;

    add_shortcode('tbhHero', 'tbhHeroShortcode');

    I have a feeling $images is not a variable and can’t be looped through.

    fixing invalid argument supplied for foreach() problem

Share This Page

Monarch Social Sharing Plugin