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()?> |