You should be able to do that with:
/**
* Setup a custom hook before the second post on the search page
*/
add_action( 'the_post', function( $post, \WP_Query $q )
{
if( $q->is_search() && $q->is_main_query() && 2 === $q->current_post )
{
do_action( 'wpse_before_second_post_in_search' );
}
}, 10, 2 );
/**
* Inject a Div after the first post on the search page
*/
add_action( 'wpse_before_second_post_in_search', function()
{
echo '<div>My Injected Div</div>';
} );
where we’ve introduced the custom wpse_before_second_post_in_search
hook, that you can now play with as you need.
Related Posts:
- grep for special characters in Unix
- how to limit search to post titles?
- How do I remove Pages from search?
- Remove some pages from search
- Remove meta robots tag from wp_head
- Template issues getting ajax search results
- How do I filter the search results order?
- How do I search events between two set dates inside WP?
- Do I need to sanitize WordPress search query?
- Search Using Post ID
- template_include for search.php makes WordPress think its on the home page
- Add custom parameters to JSON API search query?
- Include custom table into search results
- ElasticPress Indexing multiple sites
- How to search through pdf media files?
- WordPress Single Conditional for Search Page
- Does WP search natively return results sorted by type (post, post type, page, category…)?
- How do I properly redirect outbound links with special characters
- Do not allow to search certain words
- get_query_var(‘s’) not working
- Display title for search engine visitors
- How to avoid the specific page while searching in WordPress without plugin?
- How to show a random selection of posts from the search
- Related Tags Concept
- Default WP search excluding specific characters, is it possible?
- Comparing between a negative and positive number
- Get search term not on searh results page?
- Search Result from another wordpress website
- Searching by meta values showing inappropriate result
- Search by keywords with boolean operators
- Change default search URL slug in wordpress with Custop Post Type as Search target
- Redirect All Search Links Containing – to + on WordPress
- How to make wordpress Dynamic Search-Bar from Predesigned Static Html Search-Bar?
- Change Search url slug for each site in a multisite network
- Change WordPress search Permalink structure
- URL search link for ‘category__and’ instead of php query
- Search media by title and description – Frontend
- Media searching ignored
- Is there a way to add a custom text + link above search results for different searches?
- How to change tab’s title in search results pages? [closed]
- Customise Excerpt start and end
- Use created page as search results page and custom template
- How do I search dynamically created content?
- Template issues getting ajax search results
- How can I implement Search feature for Membership site?
- WordPress search with quotations returning to homepage
- Post 2 Post Site Search
- Using search.php without a ‘s’ field in searchform.php
- How to display search results in search.php
- Add Icon to Placeholder Text in Search Form
- Unexpected esc_html and esc_attr behaviour
- Search WooCommerce Products in WordPress
- Search Results No Link
- Sort search results by Custom Field
- How to build an advanced search form by post type?
- some one help . search not jump to search page
- Why should we use the name attribute with the value “s” in the creation of the search form?
- The Search FoRM Dilemma || The Search form Templating
- Search for anything in site
- How can I add search box in single.php?
- Connecting Google Site Search with WordPress Taxonomies/Categories/Tags
- When clicking on submit from my searchform it takes me to home.php
- My default search is not working
- Dashboard search function doesn’t work well
- Only display post content in search results
- meta post search
- twentyeleven theme: Where is the code that handles moving the search bar on resize?
- Displaying a list of tags in my archives page
- search page not found? (search.php or searchpage.php)
- Page 2 of Search Results shows homepage
- Media Library / Backend: How can I search for text in the ALT Text field?
- Rewrite wp function
- Return All Tags from Search Result in Separate List
- How to fetch Email addres of an author via ID?
- How to Fix Form elements do not have associated labels in WordPress Search Form (without button)
- How to exclude specific post_type from default search?
- how to make search with two input boxes
- WordPress search with more input fields?
- Search issue on special Character
- WordPress search not able to find the category
- Modify main search form to search user too
- Removing &submit=Search from search parameters?
- I have dynamic title tag in my wordpress but seo analyst show “No title Tag found error”?
- customize search result in wordpress
- pre_get_posts improperly searching revisions
- Highlight search words in excerpt
- $_GET value is losing it’s space
- Search For Custom Post Type and Custom Fields
- Searching on my blog is not working
- Make the title and […] clickable in result search
- Search multiple custom post types with tags
- wp_redirect and search engine bots
- Strip the + symbol from the_search_query
- Error when searching without any results
- Listing parent section in search results
- Putting Text in the Search Box. eg- “Search My Site” [closed]
- How to remove search bar from the blog post
- Search and replace titles of posts with specific tags
- How do I turn this form into a search form? [closed]
- How make Autocomplete with wp_query in post_type attachment