0

I add shortcode to Wordpress theme functions.php file but have, a problem. This code "[logos]" return only:

http://mydomain.pl/wp-content/uploads/2017/04/file1.pnghttp://mydomain.pl/wp-content/uploads/2017/04/file2.pnghttp://mydomain.pl/wp-content/uploads/2017/04/file3.pnghttp://mydomain.pl/wp-content/uploads/2017/04/file4.png

form custom field, but do not return HTML code.

function subscribe_link_shortcode() {

    $html = '<div>
             <h3>' . $mastertitle . '</h3>
             <div class="cmsms_clients_slider" id="cmsms_clients_slider553e45022ef2d">

              <script>
                jQuery(document).ready(function() {
                  jQuery(\'#cmsms_clients_slider553e45022ef2d\').cmsmsClientsSlider({
                    sliderBlock : \'#cmsms_clients_slider553e45022ef2d\',
                    sliderItems : \'.cmsms_clients_items\',
                    clientsInPage : 5
                  });
                });
              </script>

              <a href="javascript:void(0);" class="cmsms_clients_slider_arrow_prev"></a>
              <a href="javascript:void(0);" class="cmsms_clients_slider_arrow_next"></a>
              <ul class="cmsms_clients_items" style="width: 1161px; margin-left: 0px;">
            ';

            // WP_Query arguments
            $args = array(
              'post_type' => array( 'logo' ),
            );

            // The Query
            $query = new WP_Query( $args );

            // The Loop
            if ( $query->have_posts() ) {
              while ( $query->have_posts() ) {
                $query->the_post();

                $html .= '<li class="cmsms_clients_item" style="width: 232px;">
                  <img width="165" src="' .the_field('obrazek_logo'). '" class="cmsms_clients_img cmsms_animated" style="height: auto;">
                </li>';
              }
            } else {
              // no posts found
            }

            // Restore original Post Data
            wp_reset_postdata();

            $html .= '
                  </ul>
                </div>
              </div>';
    ;

    return $html;
}
add_shortcode('logos', 'subscribe_link_shortcode');

Anyone know why?

1
  • I copied this to my local install. I couldn't completely replicate your issue but with your code I was about to output a <ul> with <li> items in it. Do you have any php or console errors. WP_Degug set to true? I used <?php echo do_shortcode('[logos]');?> in a page template file. Commented Apr 7, 2017 at 10:42

1 Answer 1

1

As per the above code, site must be blank screen, as there is string parsing error. However, I have changed code little bit. Please, try this.

$html =  '<div>
               <h3>' . $mastertitle . '</h3>
                   <div class="cmsms_clients_slider" id="cmsms_clients_slider553e45022ef2d">

                       <script>
                            jQuery(document).ready(function() {
                                        jQuery("#cmsms_clients_slider553e45022ef2d").cmsmsClientsSlider({
                                        sliderBlock : "#cmsms_clients_slider553e45022ef2d",
                                        sliderItems : ".cmsms_clients_items",
                                        clientsInPage : 5
                                      });
                                    });
                                  </script>

                                  <a href="javascript:void(0);" class="cmsms_clients_slider_arrow_prev"></a>
                                  <a href="javascript:void(0);" class="cmsms_clients_slider_arrow_next"></a>
                                  <ul class="cmsms_clients_items" style="width: 1161px; margin-left: 0px;">
                                  ';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.