You could try replacing the extra <br />
at the beginning of the shortcode content.
You could achieve that in many ways, but here’s an example:
if( '<br />' === substr( ltrim( $content ), 0, 6 ) )
$content = substr( ltrim( $content ), 6 );
return '<div class="pncode">' . $content . '</div>';
where we play with the substr()
and ltrim()
functions.
Update:
Thanks to @userabuser for his comment.
If we want to remove all variations of br
tags, from the beginning of the shortcode string, we might try to construct this kind of reg-ex replacement:
$content = preg_replace( '#^\s*(<br\s*/?>\s*)+#i', '', $content );
Example:
The shortcode content:
<br /> <br>
<BR> <bR>
some sample code <br />
some sample code <br />
some sample code <br />
would display as:
some sample code <br />
some sample code <br />
some sample code <br />
Related Posts:
- How to add stylesheets only to pages with specific shortcode?
- Hide/show content starting in the middle of a paragraph
- How to add ‘class’ attribute into shortcode [audio]?
- Shortcode perfomance solution
- How to link to a alternative page in CSS
- Video size and border radius using a shortcode
- How can I included CSS to a page or a shortcode? [closed]
- Two different inner shortcode under shortcodes or multiple nesting of inner shortcodes
- Make shortcode’s Bootstrap CSS override the theme’s CSS, how?
- How to type shortcode-like text in WordPress TinyMCE visual editor?
- Preserve shortcode content formatting
- Documentation for adding a tinyMCE view for visual live preview of custom shortcode?
- Placing tags on wordpress visual editor using shortcodes
- How to make shortcode which returns HTML?
- How to display html element and php string in the same line?
- the_excerpt displaying code inside style tag
- How to fix transparency in product sliders / featured products on home page?
- Loading shortcode stylesheet only when shortcode is in text widget [closed]
- Shortcode templates
- How to Convert Shortcode into a link?
- How to create a shortcode with 1 parameter (atts)
- shortcodes output before content [duplicate]
- WordPress adds br in between my shortcode
- Shortcodes, HTML tables, and multiple rows
- WP_enqueue_script inside shortcode?
- Shortcode to Gutenberg-block: additional text on front-end and conditional display
- How navigation works in custom loop within shortcode?
- I dont want to show shortcode in tag
- How do I preview the result of a shortcode in the TinyMCE editor?
- WordPress shortcode doesn’t working on HomePage
- Font Awesome Icons Won’t Work
- How to Get a part of URL and put in shortcode?
- Get shortcode attribute outside of WordPress
- Overriding shortcode $atts for featured products
- Is there any inherent difference between add_filter() and add_shortcode() for modifying [caption]?
- get_shortcode_regex() only matches first shortcode
- Looking for a way to include/embed text from a file on a page so that the short codes are processed
- How do I debug a short code?
- Does registering multiple shortcodes impact performance?
- How can I hide the Permalink/Shortlink for certain user logged in Users of a certain level?
- How to force that styles are enqueued in the header?
- add action only if gallery shortcode attribute is equal to?
- How To Conditionally Include A Short Code Depending On The HTTP_REFERER [closed]
- Shortcode for order number [closed]
- Create shortcode in WordPress, using one variable in 3 functions?
- Adding javascript actions to words in post content
- My shortcode does not call the function
- Hide Selection of Text From Archive, but Show on Single Posts
- How to create an incremental list using shortcodes?
- How to Generate html tags using shortcodes?
- Do shortcode that is inserted in a textarea is not displaying properly
- How to Make Archive ShortCode
- Adding custom form within add_shortcode
- Are Shortcode Attributes Always Passed As Strings?
- wp_editor not rendering the shortcode
- Default WordPress shortcodes not working?
- how to add shortcode in wordpress container [duplicate]
- How to make this shortcode work for post content wordpress [duplicate]
- Show class from css in format dropdown
- stop WordPress removing shortcode from content [closed]
- caption shortcode using image alt as caption
- Is it possible to handle two or more shortcodes in a single page?
- Toggle Shortcode Sanitize Title
- Clearfix Shortcode
- How and when to include shortcode source files
- Use full size images in a specific gallery
- how to create a fav icon shortcode?
- How to deal with WordPress bug: can’t use wrapped and unwrapped shortcode on same post
- Execute Shortcodes when submitting post
- Substituting value via shortcode
- Create shortcode for each form field in contact form 7
- Can’t render shortcode when html tag contains hyphen
- Auto embeds don’t work for attachment descriptions
- Shortcode to appear and show the date not code in Title and description of Social Media sites
- how to add shortcode widget at end of main blog page
- Shortcode result appears above page content
- Shortcode is not showing content when placed in editor (post_type = page)
- How to set up posts per page on WP
- How to insert a short code into Contact Form 7 in WordPress that will call a function once the submit button is pressed
- Unable to make shortcode, what is wrong?
- Multiple shortcodes only use attributes from one of the shortcodes on custom plugin
- How do i remove Business feeds Shortcode fatal error
- Can’t place endwhile in the loop properly in a shortcode
- Push Shortcode parameter to template
- latest posts shortcode with image
- Shortcode tags appear on mobile themes
- WordPress Gallery with ID’s Shortcode not Working
- Featured image with link to post shortcode, image displaying above the post
- Video shortcode inside tabs shorcode NOT working
- How to stop unwanted splits in excerpts when using shortcodes for sliders or players
- How to add meta slider lite or other slider to main page header in pinboard theme
- Str_replace using shortcode with multiple changes
- div having different appearances in different themes
- Escaping a shortcode so it displays as-is [duplicate]
- WordPress do_shortcode first iteration
- Add a short code to a plugin
- Applying if (get_post_meta) to new shortcode
- Add widget/shortcode to sidebar OUTSIDE of the theme
- How to remove https:// from shortcode generated url
- How to use multiple values in “Shortcode”? [closed]