Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<br /> and dashicons in frontend #176

Open
hupe13 opened this issue Sep 19, 2022 · 2 comments
Open

<br /> and dashicons in frontend #176

hupe13 opened this issue Sep 19, 2022 · 2 comments

Comments

@hupe13
Copy link
Collaborator

hupe13 commented Sep 19, 2022

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
Copy link
Owner

bozdoz commented Sep 20, 2022

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
Copy link
Collaborator Author

hupe13 commented Sep 20, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants