Opened 4 years ago
Closed 4 years ago
#10232 closed enhancement (invalid)
Add new hooks called after template parts are loaded
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Template | Version: | 2.8 |
| Severity: | normal | Keywords: | has-patch |
| Cc: |
Description
At this moment functions get_header() and other similar ones do actions get_header, etc. at the beginning. I have changed them (see attached patch) to also do post_get_header, etc. actions at the end.
In particular I need post_get_sidebar action for my plugin, to distinguish cases when loop_start/loop_end actions are called for main post list from these in sidebar widgets.
Attachments (2)
Change History (10)
- Milestone 2.8.1 deleted
- Resolution set to invalid
- Status changed from new to closed
in them, verify that wp_query === wp_the_query. if true you're in the main loop.
sirzooro: Do you have any objections to the idea of using loop_start? Do you have a specific use which would make sense for extra hooks? (If so, reopen)
My understanding of his report is he's love to use loop_start/loop_end, but didn't know how to check whether we're in the main loop or not. Maybe we should document this somewhere in the codex or the php docs.
@Denis: you are right. I will check your suggestion later today. Hope it will work as expected :)
- Milestone set to 2.8.1
- Resolution invalid deleted
- Status changed from closed to reopened
I have checked following code but it does not work as expected - test string was displayed above posts and above entries in recent post list. Could you check this?
function loop_start_handler() {
global $wp_query, $wp_the_query;
if ( $wp_query === $wp_the_query ) {
echo '<p style="color:red">TEST</p>';
}
}
try this instead:
function loop_start_handler(&$wp_query) {
global $wp_the_query;
if ( $wp_query === $wp_the_query ) {
echo '<p style="color:red">TEST</p>';
}
}
I've a few plugins that look for the main loop only, and it's working great on my end.

use the loop_start and loop_end hooks.