You’ve got the $content available to you in your remove_p function – so inside that function just look for the existence of a special string (i.e. your “shortcode”), to allow the filter to do the str_replace. For example:
if ( false !== strpos( $content, "[p-filter]") ) {
$paragraphs = array("<p>","</p>","[p-filter]");
$noparagraphs = array("","<br>","");
return str_replace( $paragraphs, $noparagraphs, $content );
}
else
return $content;
This will work as long as your client doesn’t want to turn on/off your filter multiple times within a single POST object…if he does then it could still be done, but will be more complicated to implement.
Related Posts:
- str_replace function in theme
- The_content and Preg_replace in loaded Iframe [closed]
- opening links in new tab using – add_filter( ‘the_content’, ‘make_clickable’);
- Default or Preset Content for Custom Post Types
- Problem with extract() with custom shortcode
- Adding body class when post contains a specific shortcode
- Function to show only first instance of shortcode
- Pass Shortcode Attribute to footer Script
- Super simple shortcode not working
- How would go about if I just want a temporary function?
- Adding HTML to the end of every post with the Block Editor
- How to filter $content in shortcode function
- Insert image in WordPress with HTML5 tag and caption function
- Redirect to another page using contact form 7? [closed]
- Add Element as a Filter to the_content
- Use a shortcode to display custom meta box contents
- Wp-query Order By problem
- login_headertitle is deprecated since version 5.2.0
- Native gallery custom html output
- Insert Content Before div#main from the functions.php File
- Problem with images URL after filter applying
- Customizing the wp_video_shortcode output with add_filter
- Save_post – Warning: Cannot modify header information
- Shortcode to insert default text and change one word throughout it?
- Remove External Links from WordPress posts Using add_filter() in Theme functions.php
- $content is empty while using DOMDocument
- Hide disclaimer from summary excerpts
- How To Show Shortcodes In WordPress Custom Fields?
- How to make an If Else on Excerpt Filter
- Problem in outputting shortcode
- restrict access to specific urls on a specific period of time
- child_of not working while searching
- Creating mixture of shortcodes to use in the visual/text editor
- multible shortcodes (for differnt values) with one function
- Pagination not working – FrontPage
- Filter works on last selection but no others
- Overwrite text in a complicated filter hook
- How to replace ACTION url from original wordpress login form?
- Header menu aligned right on all pages except for single-post page [closed]
- How to add HTML into error message
- page shows short code not output
- Probleme shortcode with list author
- How to use WP conditional tag in a functions.php with OCEANWP Theme?
- custom error message for empty username and password using authenticate filter not working
- Removing comment lines from all enqueued js files using a filter function
- Modifying a WordPress Plugin
- Having trouble creating two shortcodes, one for logged in user and one for visitors
- Function to function shortcode help [closed]
- Last updated posts shortcode in functions.php
- CF7 select value get to function and reciept value from function
- Hide author info in single posts by certain users
- Add #primary at the end of navlink permalinks on single posts
- post value to function with Ajax and jQuery
- How to add a custom class attribute into code wrapper? [duplicate]
- External api call and make global variable for any page visitor enters , page-home, page, single etc
- How Do I Unhook This Parent Theme Function?
- remove_filter function to unhook twentysixteen parent theme function
- CSS style and app.js not loading
- Allow user only create specific tags
- only update titles of single posts
- OOP Switch statement with array as parameter
- I want to display the sku in the product pages of my EDD website
- How to bind each “the_content” elements to a custom variables
- Parent category as WOOCommerce Categories widget title
- Child theme remove parent filter in functions
- Shortcode to output category description by passing ID
- How to wrap pattern-matches from the_content in [wiki]-shortcode tags
- Help using ShortCodes to style whole chunks of the post
- Extend WordPress Audio Widget to accept HLS (.m3u8) URLs
- Reload page with a different shortcode when a user selects from a dropdown
- How can I automatically delete comments that contain a URL?
- Appending „read more” to the excerpt conditionally
- Strip all HTML tags from product content and resave
- How to add class dynamically from templates
- Prevent function from triggering on current page
- use add_action in a shortcode (gravity form – WordPress)
- Assign IDs to headings in ACF using functions.php
- I want to customize the_posts_navigation function by replacing prev and next with images
- How Can I Concatenate A String With One Of My Custom Field Value Before Saving The Post?
- function replace_text for entire page
- How would I correctly implement a new if statement in a child functions file?
- Shortcode displaying outside the div [duplicate]
- Woocommerce custom calculation function
- add product thumbnail to checkout page only and include variation name
- Redirect specific author posts to another url
- Remove all video attachment, both files and post/postmeta from database?
- Shortcode Initialization in a Custom Theme
- WordPress Ajaxifying not working properly
- Shortcode with pagination advancing multiple queries
- ACF Filter return value
- WordPress function with attribute pass to template
- Will dequeueing in child theme functions.php file prevent Google Fonts from loading?
- Graphic before title – Specific Category
- Which method is more correct for removing WooCommerce Extensions menu item?
- Show users last read posts for each user?
- Get shortcode attribute value to another function
- How to retrieve image IDs from shortcode content?
- Display list of pages that contain a certain string within the slug
- True email confirmation for registration (keeping unvalidated users from user table)
- HowTo: Add wrapper to columns shortcode?