' tag. add_action( 'wp_footer', 'bayleaf_svg_icons', 9999 ); /* * Wrapper functions for displaying site items. * * WordPress core 'add_action()' does not allow to * 1. Pass variables to the called function (Predefined variables in do_action() * can only be passed). * 2. No provision for conditional check before calling a function. * * Therefore, we have to create wrapper functions. Also, these wrapper functions * make code more redable. */ /** * Conditionally display skip link. * * @since 1.0.0 */ function bayleaf_skip_link() { printf( '', esc_html__( 'Skip to content', 'bayleaf' ) ); } /** * Header items wrapper markup. * * @since 1.0.0 */ function bayleaf_header_items() { bayleaf_markup( 'header-items', [ 'bayleaf_site_branding', 'bayleaf_main_navigation', 'bayleaf_user_action_items', ] ); } /** * Custom header image markup. * * @since 1.0.0 */ function bayleaf_header_image_area() { if ( ! is_home() && ! is_front_page() ) { return; } if ( is_singular() && has_post_thumbnail() ) { $img = [ 'the_post_thumbnail', 'bayleaf-featured' ]; } elseif ( get_header_image() ) { $img = 'the_header_image_tag'; } else { return; } echo '
'; bayleaf_markup( 'header-image', [ $img ] ); if ( bayleaf_get_mod( 'bayleaf_display_site_desc', 'none' ) ) { bayleaf_get_template_partial( 'template-parts/header', 'site-desc' ); } echo '
'; } /** * Site branding wrapper markup. * * @since 1.0.0 */ function bayleaf_site_branding() { $site_branding = [ 'the_custom_logo' ]; if ( bayleaf_get_mod( 'bayleaf_display_site_title', 'none' ) ) { array_push( $site_branding, [ 'bayleaf_get_template_partial', 'template-parts/header', 'site-title' ] ); } bayleaf_markup( 'site-branding', $site_branding ); } /** * Main navigation markup. * * @since 1.0.0 */ function bayleaf_main_navigation() { if ( ! bayleaf_get_mod( 'bayleaf_primary_nav', 'none' ) ) { return; } printf( '', esc_html__( 'Site Navigation', 'bayleaf' ) ); // WPCS xss ok. bayleaf_nav_menu( 'site-navigation', esc_html__( 'Site Navigation', 'bayleaf' ), [ 'menu_id' => 'primary-menu', 'menu_class' => 'nav-menu nav-menu--primary', 'container' => 'div', 'container_id' => 'menu-container', 'container_class' => 'menu-container', 'theme_location' => 'primary', ] ); } /** * Sidebar widgets wrapper markup. * * @since 1.0.0 */ function bayleaf_user_action_items() { bayleaf_markup( 'header-widgets', [ 'bayleaf_header_widgets', ] ); } /** * Sidebar widgets wrapper markup. * * @since 1.0.0 */ function bayleaf_header_widgets() { printf( '', esc_html__( 'Show secondary sidebar', 'bayleaf' ) ); // WPCS xss ok. echo '
'; if ( is_active_sidebar( 'sidebar' ) ) { bayleaf_widgets( 'header-widget-wrapper', 'header-widget-wrapper', esc_html__( 'Header Widget Wrapper', 'bayleaf' ), 'sidebar' ); } else { echo '
'; echo '
'; get_search_form(); echo '
'; } echo '
'; } /** * Social navigation markup. * * @since 1.0.0 */ function bayleaf_social_menu() { if ( ! has_nav_menu( 'social' ) ) { return; } bayleaf_nav_menu( 'social-navigation', esc_html__( 'Social Navigation', 'bayleaf' ), [ 'menu_id' => 'social-menu', 'menu_class' => 'nav-menu nav-menu--social', 'theme_location' => 'social', 'depth' => 1, 'link_before' => '', 'link_after' => '' . bayleaf_get_icon( [ 'icon' => 'chain' ] ), ] ); } /** * Display Homepage widgets 1 (widget area). * * @since 1.0.0 */ function bayleaf_home_above_content_area() { if ( ! is_front_page() || is_paged() ) { return; } bayleaf_widgets( 'home-content-area-above', 'home-content-area-above widgetlayer flex-wrapper', esc_html__( 'Homepage Above Content Widget Area', 'bayleaf' ), 'home-widgetlayer-1' ); } /** * Display Homepage widgets 2 (widget area). * * @since 1.0.0 */ function bayleaf_home_below_content_area() { if ( ! is_front_page() || is_paged() ) { return; } bayleaf_widgets( 'home-content-area-below', 'home-content-area-below widgetlayer flex-wrapper', esc_html__( 'Homepage Below Content Widget Area', 'bayleaf' ), 'home-widgetlayer-2' ); } /** * Page Entry header wrapper markup. * * @since 1.0.0 */ function bayleaf_page_entry_header() { if ( is_front_page() ) { return; } if ( is_singular( [ 'post', 'page' ] ) ) { bayleaf_markup( 'page-entry-header', [ 'bayleaf_page_entry_header_items', [ 'bayleaf_get_template_partial', 'template-parts/post', 'entry-thumbnail' ], ] ); } } /** * Page Entry header items markup. * * @since 1.0.0 */ function bayleaf_page_entry_header_items() { $page_entry_header_items = [ 'bayleaf_entry_meta_wrapper', [ 'bayleaf_get_template_partial', 'template-parts/post', 'entry-title' ], ]; if ( has_excerpt() ) { $page_entry_header_items[] = [ 'bayleaf_markup', 'single-excerpt', [ 'the_excerpt' ] ]; } bayleaf_markup( 'page-entry-header-items', $page_entry_header_items ); } /** * Include page header display template. * * @since 1.0.0 */ function bayleaf_page_header() { bayleaf_get_template_partial( 'template-parts/page', 'page-header' ); } /** * Include blog title display template. * * @since 1.0.0 */ function bayleaf_blog_title() { if ( is_home() ) { printf( '
%s%s
', esc_html__( 'Latest from', 'bayleaf' ), esc_html__( 'The Blog', 'bayleaf' ) ); } } /** * Include main loop execution template. * * @since 1.0.0 */ function bayleaf_main_loop() { bayleaf_get_template_partial( 'template-parts/loop', 'main-loop' ); } /** * Include comment toggle template. * * @since 1.0.0 */ function bayleaf_comments_toggle() { $text = ''; if ( comments_open() ) { if ( have_comments() ) { $text = esc_html__( 'Join the Conversation', 'bayleaf' ); } else { $text = esc_html__( 'Leave a comment', 'bayleaf' ); } } else { if ( have_comments() ) { $text = esc_html__( 'Show comments', 'bayleaf' ); } } if ( $text ) { $toggle_text = sprintf( '%s', $text ); // WPCS xss ok. printf( '', $toggle_text, bayleaf_get_icon( [ 'icon' => 'angle-down' ] ), bayleaf_get_icon( [ 'icon' => 'angle-up' ] ) ); // WPCS xss ok. Variables already escaped. } } /** * Entry main content wrapper markup. * * @since 1.0.0 */ function bayleaf_entry_main_content() { bayleaf_markup( 'entry-main-content', [ 'bayleaf_entry_header_wrapper', 'bayleaf_entry_content_wrapper', 'bayleaf_entry_footer_wrapper', ] ); } /** * Entry header wrapper markup. * * @since 1.0.0 */ function bayleaf_entry_header_wrapper() { if ( ! is_singular() ) { bayleaf_markup( 'entry-header', [ [ 'bayleaf_get_template_partial', 'template-parts/meta', 'meta-categories' ], [ 'bayleaf_get_template_partial', 'template-parts/post', 'entry-title' ], ] ); } elseif ( ! is_singular( [ 'post', 'page' ] ) ) { bayleaf_entry_title_area(); } } /** * Entry header title area wrapper markup. * * @since 1.0.0 */ function bayleaf_entry_title_area() { bayleaf_markup( 'entry-header-title-area', [ 'bayleaf_page_entry_header_items', [ 'bayleaf_get_template_partial', 'template-parts/post', 'entry-thumbnail' ], ] ); } /** * Conditionally display entry meta wrapper markup. * * @since 1.0.0 */ function bayleaf_entry_meta_wrapper() { if ( ! in_array( get_post_type(), [ 'page', 'attachment' ], true ) ) { bayleaf_markup( 'entry-meta', [ 'bayleaf_entry_meta' ] ); } } /** * Include entry meta display template(s). * * @since 1.0.0 */ function bayleaf_entry_meta() { bayleaf_get_template_partial( 'template-parts/meta', 'meta-author' ); printf( '%s', esc_html__( 'on', 'bayleaf' ) ); bayleaf_get_template_partial( 'template-parts/meta', 'meta-date' ); } /** * Create featured content markup on index pages. * * @since 1.0.0 */ function bayleaf_hentry() { if ( is_singular() ) { bayleaf_entry_main_content(); } else { bayleaf_markup( 'entry-index-wrapper', [ 'bayleaf_entry_featured_content', 'bayleaf_entry_main_content', ] ); } } /** * Create featured content markup on index pages. * * @since 1.0.0 */ function bayleaf_entry_featured_content() { if ( ! is_singular() && ( bayleaf_get_mod( 'bayleaf_thumbnail_placeholder', 'none' ) || has_post_thumbnail() ) ) { bayleaf_markup( 'entry-featured-content', [ [ 'bayleaf_get_template_partial', 'template-parts/post', 'entry-thumbnail' ], [ 'bayleaf_get_template_partial', 'template-parts/meta', 'meta-permalink' ], [ 'bayleaf_sticky_post_icon' ], ] ); } } /** * Sticky Post Icon. * * @since 1.0.0 */ function bayleaf_sticky_post_icon() { if ( is_sticky() ) { bayleaf_icon( [ 'icon' => 'sticky' ] ); } } /** * Entry content wrapper markup. * * @since 1.0.0 */ function bayleaf_entry_content_wrapper() { if ( is_attachment() && wp_attachment_is_image() ) { bayleaf_get_template_partial( 'template-parts/post', 'entry-attachment' ); return; } if ( is_singular() ) { bayleaf_markup( 'entry-content', [ [ 'bayleaf_get_template_partial', 'template-parts/post', 'entry-content' ], ] ); } } /** * Entry footer wrapper markup. * * @since 1.0.0 */ function bayleaf_entry_footer_wrapper() { if ( ! is_singular() ) { return; } $type = get_post_type(); $meta = []; if ( 'post' === $type ) { $meta = [ [ 'bayleaf_get_template_partial', 'template-parts/meta', 'meta-categories' ], [ 'bayleaf_get_template_partial', 'template-parts/meta', 'meta-tags' ], ]; } elseif ( 'attachment' === $type ) { $meta = [ [ 'bayleaf_get_template_partial', 'template-parts/meta', 'meta-attachment' ], ]; } if ( $meta ) { bayleaf_markup( 'entry-footer', $meta ); } } /** * Conditionally include post author display template. * * @since 1.0.0 */ function bayleaf_post_author() { global $post; // No need to display author box on image attachment pages. if ( is_attachment() && wp_attachment_is_image() ) { return; } // Display author box on single posts, if author description is available. if ( ! is_single() || '' === get_the_author_meta( 'description', $post->post_author ) ) { return; } bayleaf_get_template_partial( 'template-parts/post', 'entry-author' ); } /** * Display post pagination on home, archive and search pages. * * @since 1.0.0 */ function bayleaf_post_pagination() { if ( is_singular() ) { return; } the_posts_pagination( array( 'mid_size' => 2, 'prev_text' => '' . esc_html__( 'Previous', 'bayleaf' ) . '' . bayleaf_get_icon( array( 'icon' => 'angle-left' ) ) . '' . esc_html__( 'Previous', 'bayleaf' ) . '', 'next_text' => '' . esc_html__( 'Next', 'bayleaf' ) . '' . esc_html__( 'Next', 'bayleaf' ) . '' . bayleaf_get_icon( array( 'icon' => 'angle-right' ) ), 'before_page_number' => '' . esc_html__( 'Page', 'bayleaf' ) . ' ', ) ); } /** * Display post navigation on single posts. * * @since 1.0.0 */ function bayleaf_post_navigation() { if ( ! is_singular( 'post' ) ) { return; } the_post_navigation( array( 'next_text' => '' . esc_html__( 'Next Post ', 'bayleaf' ) . '%title', 'prev_text' => '' . esc_html__( ' Previous Post', 'bayleaf' ) . '%title', ) ); } /** * Display image navigation on image attachment pages. * * @since 1.0.0 */ function bayleaf_image_navigation() { if ( ! ( is_attachment() && wp_attachment_is_image() ) ) { return; } ?> %1$s%2$s', bayleaf_get_icon( [ 'icon' => 'arrow-up' ] ), esc_html__( 'Scroll to top of the page', 'bayleaf' ) ); // WPCS xss ok. } /** * Display footer text. * * Escape footer text and replace year, title and symbol placeholders with * proper markup. * * @since 1.0.0 * @return void */ function bayleaf_footer_text() { // Note: Footer text is escaped via `bayleaf_escape()`. $footer_text = bayleaf_get_mod( 'bayleaf_footer_text', 'html' ); if ( '' === $footer_text ) { return; } $output = str_replace( '[current_year]', esc_html( date_i18n( __( 'Y', 'bayleaf' ) ) ), $footer_text ); $output = str_replace( '[site_title]', get_bloginfo( 'name', 'display' ), $output ); $output = str_replace( '[copy_symbol]', '©', $output ); printf( '', $output ); // WPCS xss ok. Contains HTML, other values escaped. } /** * Add SVG definitions to the site footer. * * @since 1.0.0 */ function bayleaf_svg_icons() { if ( has_nav_menu( 'social' ) ) { include_once get_parent_theme_file_path( 'assets/images/icons-with-social.svg' ); } else { include_once get_parent_theme_file_path( 'assets/images/icons.svg' ); } }