I’d say it’s perfectly fine to do it the way you’re doing it now, that is
function my_the_posts($posts, $query = false) {
if( is_search() ){
// do your thing here
}
return $posts;
}
add_filter( 'the_posts', 'my_the_posts' );
Don’t worry about those excerpts in the footer, even though they may be part of the search page (which the footer will be, obviously), they’re part of a different query and so will not pass the is_search() test.
Related Posts:
- How can I edit post data before it is saved?
- Registering Class methods as hook callbacks
- How to customize woocommerce related products? [closed]
- Hooking in to plugins
- Generate dormant hook references
- Better to fire specific hooks or generic hooks with parameters?
- How to only hook on Single.php after content?
- Why does wp_enqueue_style() in plugin not load stylesheet?
- How to save the values of checkbox to the register setting?
- Edit plugin without hooks in functions.php
- How can I log a user out of WordPress before the page loads?
- Enqueue style inside shortcode but its loaded at the bottom of page (before footer scripts)
- Modify featured image URL at runtime
- Seeking clarification on page request life-cycle
- Good tools for locating hooks in a wordpress page/admin interface/blog post?
- Hide WordPress Plugin Deactivation Links
- Pass A Value From Outside To A Plugin Variable
- Built in admin ajax hooks?
- Does the ‘nav_menu_css_class’ filter accept 2 or 3 arguments?
- do_action and hook methods
- woocommerce product attributes
- How to filter content post only on save
- Filter or action hook to insert content on admin pages before tag
- plugin_action_links_{$plugin_file} hook not in the main plugin file
- How to find out what blocks are added by a plugin
- merging an array to an existing array using add_filter
- template_redirect not being called when using ajax
- what the hook for displaying course list page for learndash plugin? [closed]
- How to add rewrite rules and pagination to retrieve attachments files?
- Plugin custom Action Hook not working
- What are the benefit in adding hook in the init() hook?
- What are ideal hooks to call register_sidebars?
- AddFilter option_active_plugins is executed 6 times. Why?
- Hook to generate a dynamic sitemap with “All in One SEO Pack” Plugin
- How to correctly detect accessing wp-content/uploads?
- Deactivate Plugin on Theme Switch
- Where to hook my plugin’s action
- How to pull code snippet from functionality plugin?
- How do action and filter hooks understand where to look for the core function that we hooked our function to them
- Add custom message to the plugins page of WordPress
- Hooking in to replace the Sidebar/Widget areas
- How to get all of the activate_plugin action parameters?
- Using a post-signup hook to get user details
- woocommerce_package_rates not fired when wordpress woocommerce accessed as non ajax
- Trigger Elementor Popup via code [closed]
- Calling plugin function inside custom plugin for onclick event
- Filtering WooCommerce Orders by Category
- do_action() hook into load-(page)
- Howto check version of another plugin and then add a submenu page to it
- Template filter for custom taxonomy terms
- Why do plugins often ask to add in to templates?
- remove_action not removing add_action from constructor
- How to get menu location in wp_update_nav_menu hook
- Can my hooked uninstall class function access a global var declared in main plugin file?
- Flipping Book PHP Code? Any experience?
- Display Plugin Panels Outside of Admin Areas
- Save user total active time after login in wordpress [closed]
- Advanced WordPress plugin activation detection
- wp_loaded with static Singleton
- How to return the values from a row where a value occurs for the first time among the rows available?
- How to hook into action/filter call
- Quick press publish post hook
- How to automatically activate users after registration without activation email?
- Creating a plugin that will display text on every page
- Hooks to run after a core upgrade?
- Adding custom Field To The Posts Listing
- Build a must-use plugin that tracks when other plugins are activated or deactivated
- Activation flow of a plugin in a multisite environment
- Add hook after content without formatting
- Using Remove Action Hook in Plugin
- admin_post hook not firing function inside class
- Alternative Hook to the_content for Changing Background Color
- Unpublished Pages Failing To Appear On Custom Path
- Replace plugin HTML to single text using hooks
- How can I disable W3 Total Cache Image Lazy Load for Specific Post Type?
- Display Woocommerce attribute name above product title
- wordpress plugin translation not working
- WordPress Boilerplate Plugin doesn’t see callback functions for add_settings_field and add_settings_section
- What is the correct entry point for capturing coverage data
- Identify if the_post hook is being called from the admin post list
- Add a filter to a method in the parent theme
- Publish check if the edited content has HTML “div”
- Passing a parameter to filter and action functions
- Run only on plug-in activation instead of wp_head
- Display_rows() and column_cb() strange behaviour
- change output location of plugin function using a custom hook
- Plugin constructor called multiple times
- How to change value of $menu_class in ep_nav_menu?
- How to create and use Custom hooks
- OOP Plugin: Where should I place the action hooks in the class?
- add query string to all pages after user logged in
- How wordpress plugin hooks works? [duplicate]
- Post curl function save twice using plugin hook function wordpress
- Order shipped by which driver[hook for woocoomerce order staus changed and popup in admin panel ] [closed]
- Hook automatic_updates_complete to autoupdate plugin
- Neither update_option nor delete_option fires in deactivation hook
- Why is my activator class adding the files/running the actions I add?
- Admin Notice is only localized when displaying the “Plugins” Backend Page
- WordPress : how to create onglet and remove it when only one
- Remove 3rd party plugin notices from within own plugin