-
Notifications
You must be signed in to change notification settings - Fork 2
/
template-tags.php
51 lines (44 loc) · 1.18 KB
/
template-tags.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Template tags.
*/
/**
* Render a component.
*
* @param string $name Component name.
* @param array $attributes Attributes to pass to component.
* @param bool $echo Echo the component.
*
* @return false|string|void
*/
function jb_component( $name = '', $attributes = [], $echo = true ) {
$path = get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR . 'index.php';
if ( ! file_exists( $path ) ) {
return false;
}
ob_start();
require $path;
$component = ob_get_clean();
if ( false === $echo ) {
return $component;
}
echo $component; // phpcs:ignore -- No need to escape it, since all escaping happens in the component.
}
/**
* Start building template content.
*/
function jb_template_header() {
ob_start();
}
/**
* Finish building template content.
*/
function jb_template_footer() {
// Get built content.
$content = ob_get_clean();
// Render built content after header.
// This is to trigger all hooks before the header is called.
get_header();
echo $content; // phpcs:ignore -- No need to escape it, since all escaping happens in the template / components.
get_footer();
}