Custom vendor list shortcode injects code both into head and body element

WCMp Core

Resolved
Viewing 3 reply threads
  • Author
    Posts
    • #130246
      Kevin
      Participant

      I’ve taken inspiration from another thread on the forum on how to create my own custom vendor list and wrap it into a shortcode.
      Other thread: https://multivendorx.com/support-forum/topic/shortcode-for-verified-accounts/#post-113330

      The issue is that on the page where I’m calling my custom shortcode, the code is somehow being injected into the <head> element (also in the <body> as expected).
      I have attached two images to illustrate.

      I have the following code in my functions.php file in my child theme:

      add_action('init', 'add_custom_vendor_list_shortcode');
      function add_custom_vendor_list_shortcode(){
      	add_shortcode('wcmp_frontpage_vendors', 'wcmp_frontpage_vendors_list');
      }
      Copy
      function wcmp_frontpage_vendors_list() {
          global $WCMp;
      	$frontend_assets_path = $WCMp->plugin_url . 'assets/frontend/';
      	$frontend_assets_path = str_replace(array('http:', 'https:'), '', $frontend_assets_path);
      	$suffix = defined('WCMP_SCRIPT_DEBUG') && WCMP_SCRIPT_DEBUG ? '' : '.min';
      	wp_register_style('wcmp_vendor_list', $frontend_assets_path . 'css/vendor-list' . $suffix . '.css', array(), $WCMp->version);
      	wp_style_add_data('wcmp_vendor_list', 'rtl', 'replace');
      	wp_enqueue_style('wcmp_vendor_list');
      	$block_vendors = wp_list_pluck(wcmp_get_all_blocked_vendors(), 'id');
      	$vendors = get_wcmp_vendors( array('exclude'   => $block_vendors), $return = 'id');
      	$verified_vendor_list = array();
      	foreach ($vendors as $vendor_id) {
      		$verified_vendor = get_user_meta( $vendor_id, '_verify_vendor', true);		
              if($verified_vendor == 'Enable' ) {
              	$verified_vendor_list[] = $vendor_id;
              }	
      	}
      	?>
          <div id="wcmp-store-conatiner">
      	     <div class="wcmp-store-list-wrap list-3">
      	        <?php
      	        if ($verified_vendor_list && is_array($verified_vendor_list)) {
      	            foreach ($verified_vendor_list as $vendor_id) {
      	                $vendor = get_wcmp_vendor($vendor_id);
      	                $image = $vendor->get_image() ? $vendor->get_image('image', array(125, 125)) : $WCMp->plugin_url . 'assets/images/WP-stdavatar.png';
      	                $banner = $vendor->get_image('banner') ? $vendor->get_image('banner') : '';
      	                ?>
      
      	                <div class="wcmp-store-list">
      	                    <?php do_action('wcmp_vendor_lists_single_before_image', $vendor->term_id, $vendor->id); ?>
      	                    <div class="wcmp-profile-wrap">
      	                        <div class="wcmp-cover-picture" style="background-image: url('<?php if($banner) echo $banner; ?>');"></div>
      	                        <div class="store-badge-wrap">
      	                            <?php do_action('wcmp_vendor_lists_vendor_store_badges', $vendor); ?>
      	                        </div>
      	                        <div class="wcmp-store-info">
      	                            <div class="wcmp-store-picture">
      	                                <img class="vendor_img" src="<?php echo esc_url($image); ?>" id="vendor_image_display">
      	                            </div>
      	                            <?php
      	                                $rating_info = wcmp_get_vendor_review_info($vendor->term_id);
      	                                $WCMp->template->get_template('review/rating_vendor_lists.php', array('rating_val_array' => $rating_info));
      	                            ?>
      	                        </div>
      	                    </div>
      	                    <?php do_action('wcmp_vendor_lists_single_after_image', $vendor->term_id, $vendor->id); ?>
      	                    <div class="wcmp-store-detail-wrap">
      	                        <?php do_action('wcmp_vendor_lists_vendor_before_store_details', $vendor); ?>
      	                        <ul class="wcmp-store-detail-list">
      	                            <li>
      	                                <i class="wcmp-font ico-store-icon"></i>
      	                                <?php $button_text = apply_filters('wcmp_vendor_lists_single_button_text', $vendor->page_title); ?>
      	                                <a href="<?php echo esc_url($vendor->get_permalink()); ?>" class="store-name"><?php echo esc_html($button_text); ?></a>
      	                                <?php do_action('wcmp_vendor_lists_single_after_button', $vendor->term_id, $vendor->id); ?>
      	                                <?php do_action('wcmp_vendor_lists_vendor_after_title', $vendor); ?>
      	                            </li>
      	                            <?php if($vendor->get_formatted_address()) : ?>
      	                            <li>
      	                                <i class="wcmp-font ico-location-icon2"></i>
      	                                <p><?php echo esc_html($vendor->get_formatted_address()); ?></p>
      	                            </li>
      	                            <?php endif; ?>
      	                        </ul>
      	                        <?php do_action('wcmp_vendor_lists_vendor_after_store_details', $vendor); ?>
      	                    </div>
      	                </div>
      	                <?php
      	            }
      	        } else {
      	            _e('No verified vendor found!', 'dc-woocommerce-multi-vendor');
      	        }
      	        ?>
      	    </div>
      	</div>
          <?php
      }
      Copy

      Anyone who has any clues on what’s going on?

    • #130273

      Hi,
      We have checked this on our end using the above code and no issue found.
      Check out the video – https://app.vmaker.com/record/4gD3GQqdpsT7DbPr

      If you are using any SEO Plugin then deactivate this plugin and check again.

      Regards,

    • #130336
      Kevin
      Participant

      We have All in One SEO plugin installed and deactivating that made the error go away – so far, so good.

      However, we would very much like to keep the plugin. Any suggestions on how to work around this?

    • #130381

      Hi,
      As this is a third party plugin, it is not possible for us to inspect the code and find the issue.
      However, if you are a developer then kindly locate the issue. If it is related to WCMp then let us know.
      We will check with our developer to give you an fix.

Viewing 3 reply threads

The topic ‘Custom vendor list shortcode injects code both into head and body element’ is closed to new replies.