Needed
ā Back to top- Minimum Requirements: Canvas V5.x
- Keep theĀ Canvas Hook/Filter ReferenceĀ on hand, as it will come in handy using the techniques explained below.
Explanation
ā Back to top- The label of the hook you want to hook onto (for example, `woo_loop_after`).
- A function which weāll use to display your custom content.
- An `add_action()` line to perform the āhookingā.
The basics
ā Back to top|
1
2
3
4
5
6
7
8
9 |
<?phpĀ Ā Ā Ā function woo_hook_content_loop_after () {Ā Ā Ā Ā Ā Ā Ā Ā $content = '';Ā Ā Ā Ā Ā Ā Ā Ā echo $content;Ā Ā Ā Ā } // End woo_hook_content_loop_after()?> |
|
1
2
3
4
5
6
7 |
<?phpĀ Ā Ā Ā function woo_hook_content_loop_after () {?><div id="test-code">This is my custom code. Replace this DIV tag with your code.</div><!--/#test-code--><?phpĀ Ā Ā Ā } // End woo_hook_content_loop_after()?> |
Advanced logic
ā Back to top|
1 |
|
|
1
2
3
4
5
6
7 |
<?phpĀ Ā Ā Ā function woo_hook_content_loop_after () {?><div id="test-code">This is my custom code. Replace this DIV tag with your code.</div><!--/#test-code--><?phpĀ Ā Ā Ā } // End woo_hook_content_loop_after()?> |
|
1
2
3
4
5
6
7 |
<?phpĀ Ā Ā Ā function woo_hook_content_loop_after () {?><?phpĀ Ā Ā Ā } // End woo_hook_content_loop_after()?> |
|
1
2
3
4
5
6
7
8
9 |
<?phpĀ Ā Ā Ā function woo_hook_content_loop_after () {Ā Ā Ā Ā Ā Ā Ā Ā if ( is_category() ) {?><?phpĀ Ā Ā Ā Ā Ā Ā Ā } // End IF StatementĀ Ā Ā Ā } // End woo_hook_content_loop_after()?> |
|
1
2
3 |
<?phpĀ Ā Ā Ā add_action( 'woo_loop_after', 'woo_hook_content_loop_after', 12 );?> |
The result produced using a custom hook in Canvas.
Finished code snippets
ā Back to top|
1
2
3
4
5
6
7
8
9
10
11 |
<?phpĀ Ā Ā Ā add_action( 'woo_loop_after', 'woo_hook_content_loop_after', 12 );Ā Ā Ā Ā function woo_hook_content_loop_after () {Ā Ā Ā Ā Ā Ā Ā Ā if ( is_category() ) {?><?phpĀ Ā Ā Ā Ā Ā Ā Ā } // End IF StatementĀ Ā Ā Ā } // End woo_hook_content_loop_after()?> |
Taking this code further
ā Back to top|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 |
<?phpĀ Ā Ā Ā add_action( 'woo_post_after', 'woo_hook_content_post_after', 12 );Ā Ā Ā Ā function woo_hook_content_post_after () {Ā Ā Ā Ā Ā Ā Ā Ā global $wp_query;Ā Ā Ā Ā Ā Ā Ā Ā $current_count = $wp_query->current_post + 1;Ā Ā Ā Ā Ā Ā Ā Ā if ( is_category() && ( $current_count == 3 ) ) {?><?phpĀ Ā Ā Ā Ā Ā Ā Ā } // End IF StatementĀ Ā Ā Ā } // End woo_hook_content_post_after()?> |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 |
<?phpĀ Ā Ā Ā add_action( 'woo_post_after', 'woo_hook_content_post_after_search', 12 );Ā Ā Ā Ā function woo_hook_content_post_after_search () {Ā Ā Ā Ā Ā Ā Ā Ā global $wp_query;Ā Ā Ā Ā Ā Ā Ā Ā $current_count = $wp_query->current_post + 1;Ā Ā Ā Ā Ā Ā Ā Ā if ( is_search() && ( $current_count % 2 == 0 ) ) {?><?phpĀ Ā Ā Ā Ā Ā Ā Ā } // End IF StatementĀ Ā Ā Ā } // End woo_hook_content_post_after_search()?> |