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
- Is it possible to remove the “standard” post format?
- Modify search function in WordPress (TwentyTwelve)
- syntax for remove_filter in parent theme with class
- Changing a function in function.php to a shortcode – for listing categories of only a certain post type
- Override parent theme function that is not hooked or in the functions.php file
- Formatting post content to exclude gallery
- Hide some items from Screen options in dashboard for products
- get_the_excerpt() not returning anything when post has no excerpt
- Replace Archive Widget Link Text
- Best way to programatically add “rel” attributes to page and post images
- creating shortcode to pull json array
- Remove function or filter
- adding custom classes for tables
- Wrap First Character after in a tag
- Searching for content post
- Display gallery on top before content
- wp_dropdown_categories and custom attribute
- Variable if post is sticky in functions.php
- Include default functions and methods
- How can I modify all existing tags while keeping the urls themselves?
- Unable to login using username
- Excerpts are not displayed by a shortcode on category pages
- shortcode help require
- Optimizing a WordPress site
- different style sheet for just one page template
- How can I add a filter for specific categories on functions.php?
- How would I go about replacing this function in my child theme located in inc/template-tags.php
- Condition OR for current user ID
- Retrieve a value from Yoast SEO to use to set a default twitter card image honoring overrides
- Insert template-part inside the content
- Visual Composer creating own shortcodes with vc_map() to return simple Image
- Where do I store custom functions that call custom page template files?
- Using multiple line variable inside a function?
- How to echo the value of an array element using a function via a shortcode
- How can I add a class to a nav li depending on URL?
- remove_action not working, even after changing priority [duplicate]
- Shortcode to get featured image of specific id post
- Replace header image on all other pages but home – URL issue
- Add a class to post if it has been recently updated
- search form leads to 404
- how to add_filter to non hook function
- How to Create custom block for displaying information in content section which act like shortcode
- Display a list of random terms from custom taxonomy with shortcode
- the_content getting current page content instead specified ID
- Overwrite text in a complicated filter hook
- CF7 select value get to function and reciept value from function
- remove_filter function to unhook twentysixteen parent theme function
- only update titles of single posts
- OOP Switch statement with array as parameter
- How can I automatically delete comments that contain a URL?
- Appending „read more” to the excerpt conditionally
- Woocommerce custom calculation function
- ACF Filter return value
- Replace image attributes for lazyload plugin on image elements with specific class
- Shortcode Function – Can’t get anything else to return after running shortcode within shortcode
- Custom shortcode with do_shortcode and substr
- functions.php filters not applied in AJAX call
- WordPress shortcode Issue!
- Settings in functions.php used by a plugin
- Pull random comment from specific post, display on homepage with shortcode
- Set thumbnail from URL, by grabbing image in functions.php
- Can’t change excerpt length and more tag
- PHP error in shortcode [closed]
- How to Add Extra Text In WordPress Title Before Post Publish
- Problem with removing characters “<” – WpAllImport
- function to show youtube videos within excerpt – if condition and apply_filters