bozdoz / wp-plugin-leaflet-map

Add leaflet maps to Wordpress with shortcodes
https://wordpress.org/plugins/leaflet-map/
GNU General Public License v2.0
140 stars 71 forks source link

<br /> and dashicons in frontend #176

Open hupe13 opened 1 year ago

hupe13 commented 1 year ago

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.

bozdoz commented 1 year ago

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)?

hupe13 commented 1 year ago

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.