wp-plugin-leaflet-map icon indicating copy to clipboard operation
wp-plugin-leaflet-map copied to clipboard

<br /> and dashicons in frontend

Open hupe13 opened this issue 1 year ago • 2 comments

Hi Bozdoz,

this code should be in Leaflet Map and not in Extensions.

function leafext_replace_br ($content) {
  $content = preg_replace( '#</script>(\s*)<br />#', '</script>', $content );
  return $content;
}
add_filter('pre_do_shortcode_tag', function ( $output, $shortcode, $attr) {
  if ( 'leaflet-marker' == $shortcode ) {
    if (isset($attr["iconclass"]) &&  str_contains($attr["iconclass"], "dashicons")) {
      wp_enqueue_style( 'dashicons' );
    }
  }
  add_filter('the_content', 'leafext_replace_br', 20, 1);
  return $output;
}, 10, 3);

dashicons see https://leafext.de/extra/helper/. leafext_replace_br: See https://wordpress.org/support/topic/huge-white-space-below-my-map-on-the-blog-posts-overview-page/#post-15980872 Searching about that with Google suggested solution with wp_autop, but this doesn't work.

hupe13 avatar Sep 19 '22 18:09 hupe13

You're getting br tags after your script tags?

Also, why check if the user is adding dashicons (not entirely opposed to this, but seems so specific)?

bozdoz avatar Sep 20 '22 00:09 bozdoz

I'm sorry, I merged two things.

You're getting br tags after your script tags?

Yes.

We are using shortcodes. The users write more than one shortcode in one shortcode block, every shortcode on one line, so that it is clearly arranged. WordPress interprets every shortcode and for the "newline" it inserts a <br />. Therefore a large empty space appears. I tested it with a standard theme also.

Also, why check if the user is adding dashicons (not entirely opposed to this, but seems so specific)?

You have in your Shortcode Helper page [leaflet-marker svg background="#777" iconClass="dashicons dashicons-star-filled" color="gold"]My Favorite Place in the World[/leaflet-marker]. The users test it and it isn't displayed correctly in frontend, because dashicons are only available in admin backend. So the function tests if dashicons are used and loads the css if needed.

If you find another solution for the problems, you can of course apply it.

hupe13 avatar Sep 20 '22 07:09 hupe13