' tag. add_action( 'wp_footer', 'aamla_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.2 */ function aamla_skip_link() { // Return if there is no content to skip to. if ( is_page_template( 'page-templates/header-blank-footer.php' ) ) { return; } printf( '%s', esc_html__( 'Skip to content', 'aamla' ) ); } /** * Header items wrapper markup. * * @since 1.0.0 */ function aamla_header_items() { aamla_markup( 'header-items', [ 'aamla_site_branding', 'aamla_user_action_items', ] ); } /** * Contact Infromation wrapper markup. * * @since 1.0.0 */ function aamla_contact_information() { $telephone = aamla_get_mod( 'aamla_tel_number', 'none' ); $email = aamla_get_mod( 'aamla_email_id', 'none' ); if ( ! ( $email || $telephone || has_nav_menu( 'social' ) ) ) { return; } aamla_markup( 'contact-information', [ [ 'aamla_get_template_partial', 'template-parts/header', 'contact-info' ] ] ); } /** * Site branding wrapper markup. * * @since 1.0.0 */ function aamla_site_branding() { aamla_markup( 'site-branding', [ 'aamla_site_logo', 'aamla_branding_text', ] ); } /** * User actionable items wrapper. * * @since 1.0.0 */ function aamla_user_action_items() { if ( is_active_sidebar( 'header' ) ) { aamla_markup( 'header-widgets', [ 'aamla_header_widgets' ] ); } if ( aamla_get_mod( 'aamla_header_search', 'none' ) ) { get_search_form(); } } /** * User actionable items wrapper. * * @since 1.0.0 */ function aamla_header_widgets() { printf( '', aamla_get_icon( [ 'icon' => 'more' ] ), esc_html__( 'Show possible user actions', 'aamla' ) ); // WPCS xss ok. aamla_widgets( 'header-widget-area', 'header-widget-area', esc_html__( 'Header Widget Area', 'aamla' ), 'header' ); } /** * Site logo display function. * * @since 1.0.0 */ function aamla_site_logo() { the_custom_logo(); } /** * Include header text display template. * * @since 1.0.0 */ function aamla_branding_text() { $title_area = []; if ( aamla_get_mod( 'aamla_display_site_title', 'none' ) ) { array_push( $title_area, [ 'aamla_get_template_partial', 'template-parts/header', 'site-title' ] ); } if ( aamla_get_mod( 'aamla_display_site_desc', 'none' ) ) { array_push( $title_area, [ 'aamla_get_template_partial', 'template-parts/header', 'site-desc' ] ); } if ( ! empty( $title_area ) ) { aamla_markup( 'title-area', $title_area ); } } /** * Main navigation markup. * * @since 1.0.0 */ function aamla_main_navigation() { if ( ! aamla_get_mod( 'aamla_primary_nav', 'none' ) ) { return; } aamla_nav_menu( 'site-navigation', esc_html__( 'Site Navigation', 'aamla' ), [ 'menu_id' => 'primary-menu', 'menu_class' => 'nav-menu nav-menu--primary', 'container' => 'div', 'container_id' => 'menu-container', 'container_class' => 'menu-container wrapper', 'theme_location' => 'primary', ] ); } /** * Page Entry header wrapper markup. * * @since 1.0.0 */ function aamla_page_entry_header() { if ( is_singular( 'page' ) && has_post_thumbnail() ) { aamla_markup( 'page-entry-header', [ 'aamla_page_entry_header_items', [ 'aamla_get_template_partial', 'template-parts/post', 'entry-thumbnail' ], ] ); } } /** * Call available breadcrumb display function. * * @since 1.0.0 */ function aamla_breadcrumb() { // Let's not display breadcrumbs on the front page. if ( is_front_page() ) { return; } // First use 'Breadcrumb NavXT' function (if available). if ( function_exists( 'bcn_display' ) ) { printf( '
', bcn_display( true ) ); // WPCS xss ok. Using specific plugin's display safe function. return; } // Next use 'Breadcrumb Trail' Plugin's function (if available). if ( function_exists( 'breadcrumb_trail' ) ) { breadcrumb_trail(); return; } // Lastly use 'Yoast Breadcrumb' function (if available). if ( function_exists( 'yoast_breadcrumb' ) ) { yoast_breadcrumb( '' ); } } /** * Include page header display template. * * @since 1.0.0 */ function aamla_page_header() { aamla_get_template_partial( 'template-parts/page', 'page-header' ); } /** * Include main loop execution template. * * @since 1.0.0 */ function aamla_main_loop() { aamla_get_template_partial( 'template-parts/loop', 'main-loop' ); } /** * Entry main content wrapper markup. * * @since 1.0.0 */ function aamla_entry_main_content() { aamla_markup( 'entry-main-content', [ 'aamla_entry_header_wrapper', 'aamla_entry_content_wrapper', 'aamla_entry_footer_wrapper', ] ); } /** * Entry header wrapper markup. * * @since 1.0.0 */ function aamla_entry_header_wrapper() { if ( is_single() ) { // Display title-area on single posts. $entry_header = [ 'aamla_entry_title_area' ]; // Check if post thumbnails to be displayed on single posts. if ( aamla_get_mod( 'aamla_thumbnail_on_single', 'none' ) ) { $entry_header[] = [ 'aamla_get_template_partial', 'template-parts/post', 'entry-thumbnail' ]; } } else { // If singular page having a thumbnail, its title display will be handled separately. if ( is_singular( 'page' ) && has_post_thumbnail() ) { return; } // Display entry title on index and single ('page' & 'attachment' post-types) pages. $entry_header = [ [ 'aamla_get_template_partial', 'template-parts/post', 'entry-title' ] ]; } aamla_markup( 'entry-header', $entry_header ); } /** * Page Entry header items markup. * * @since 1.0.0 */ function aamla_page_entry_header_items() { aamla_markup( 'page-entry-header-items', [ [ 'aamla_get_template_partial', 'template-parts/post', 'entry-title' ], 'aamla_page_excerpt', ] ); } /** * Page excerpt display function. * * @since 1.0.0 */ function aamla_page_excerpt() { // Remove 'script' and 'style' tag and their contents. $excerpt = preg_replace( '@<(script|style)[^>]*?>.*?\\1>@si', '', get_the_excerpt() ); // Remove html tags except 'p' and 'a' tags. $excerpt = strip_tags( $excerpt, '' );
if ( $excerpt ) {
$dom = new DOMDocument();
$dom->loadHTML( $excerpt );
// Get all links within 'a' tag in page excerpt.
$links = $dom->getElementsByTagName( 'a' );
// Iterate over the extracted links and escape their URLs.
foreach ( $links as $link ) {
$url = $link->getAttribute( 'href' );
if ( $url ) {
$link->removeAttribute( 'href' );
$link->setAttribute( 'href', esc_url( $url ) );
}
}
$excerpt = $dom->saveHTML();
printf( '
'sticky' ] );
}
}
/**
* Entry content wrapper markup.
*
* @since 1.0.0
*/
function aamla_entry_content_wrapper() {
if ( is_attachment() && wp_attachment_is_image() ) {
aamla_get_template_partial( 'template-parts/post', 'entry-attachment' );
return;
}
aamla_markup( 'entry-content', [ 'aamla_entry_content' ] );
}
/**
* Include entry content display template.
*
* @since 1.0.0
*/
function aamla_entry_content() {
if ( is_singular() ) {
aamla_get_template_partial( 'template-parts/post', 'entry-content' );
} else {
the_excerpt();
aamla_get_template_partial( 'template-parts/meta', 'meta-categories' );
}
}
/**
* Entry footer wrapper markup.
*
* @since 1.0.0
*/
function aamla_entry_footer_wrapper() {
if ( ! is_singular() ) {
return;
}
if ( in_array( get_post_type(), array( 'post', 'attachment' ), true ) ) {
aamla_markup( 'entry-footer', [ 'aamla_footer_meta' ] );
}
}
/**
* Include entry footer display template(s).
*
* @since 1.0.0
*/
function aamla_footer_meta() {
if ( 'post' === get_post_type() ) {
aamla_get_template_partial( 'template-parts/meta', 'meta-categories' );
aamla_get_template_partial( 'template-parts/meta', 'meta-tags' );
} else {
aamla_get_template_partial( 'template-parts/meta', 'meta-attachment' );
}
}
/**
* Conditionally include post author display template.
*
* @since 1.0.0
*/
function aamla_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;
}
aamla_get_template_partial( 'template-parts/post', 'entry-author' );
}
/**
* Display post pagination on home, archive and search pages.
*
* @since 1.0.0
*/
function aamla_post_pagination() {
if ( is_singular() ) {
return;
}
the_posts_pagination( array(
'mid_size' => 2,
'prev_text' => '' . esc_html__( 'Previous', 'aamla' ) . '' . aamla_get_icon( array( 'icon' => 'angle-left' ) ) . '' . esc_html__( 'Previous', 'aamla' ) . '',
'next_text' => '' . esc_html__( 'Next', 'aamla' ) . '' . esc_html__( 'Next', 'aamla' ) . '' . aamla_get_icon( array( 'icon' => 'angle-right' ) ),
'before_page_number' => '',
) );
}
/**
* Display post navigation on single posts.
*
* @since 1.0.0
*/
function aamla_post_navigation() {
if ( ! is_singular( 'post' ) ) {
return;
}
the_post_navigation( array(
'next_text' => '%title',
'prev_text' => '%title',
) );
}
/**
* Display image navigation on image attachment pages.
*
* @since 1.0.0
*/
function aamla_image_navigation() {
if ( ! ( is_attachment() && wp_attachment_is_image() ) ) {
return;
}
?>
%1$s', $output ); // WPCS xss ok. Contains HTML, other values escaped.
}
/**
* Add SVG definitions to the site footer.
*
* @since 1.0.0
*/
function aamla_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' );
}
}