| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Displays transparent logo on Cover & Transparent Header templates. |
| 5 |
*/ |
| 6 |
function twentig_logo_transparent( $html ) { |
| 7 |
|
| 8 |
$custom_logo_id = get_theme_mod( 'custom_logo' ); |
| 9 |
$custom_logo_transparent_id = get_theme_mod( 'twentig_custom_logo_transparent' ); |
| 10 |
|
| 11 |
if ( ! $custom_logo_id || ! $custom_logo_transparent_id ) { |
| 12 |
return $html; |
| 13 |
} |
| 14 |
|
| 15 |
// We have a logo. Logo is go. |
| 16 |
if ( is_page_template( array( 'templates/template-cover.php', 'tw-header-transparent-light.php' ) ) ) { |
| 17 |
$custom_logo_attr = array( |
| 18 |
'class' => 'custom-logo', |
| 19 |
); |
| 20 |
|
| 21 |
$image_alt = get_post_meta( $custom_logo_id, '_wp_attachment_image_alt', true ); |
| 22 |
if ( empty( $image_alt ) ) { |
| 23 |
$custom_logo_attr['alt'] = get_bloginfo( 'name', 'display' ); |
| 24 |
} |
| 25 |
|
| 26 |
if ( get_theme_mod( 'twentig_header_sticky' ) ) { |
| 27 |
$custom_logo_attr['class'] = 'custom-logo logo-primary'; |
| 28 |
$custom_logo_transparent_attr = $custom_logo_attr; |
| 29 |
$custom_logo_transparent_attr['class'] = 'custom-logo logo-transparent'; |
| 30 |
|
| 31 |
$html = sprintf( |
| 32 |
'<a href="%1$s" class="custom-logo-link" rel="home">%2$s</a>', |
| 33 |
esc_url( home_url( '/' ) ), |
| 34 |
wp_get_attachment_image( $custom_logo_id, 'full', false, $custom_logo_attr ) . ' ' . |
| 35 |
wp_get_attachment_image( $custom_logo_transparent_id, 'full', false, $custom_logo_transparent_attr ) |
| 36 |
); |
| 37 |
} else { |
| 38 |
$html = sprintf( |
| 39 |
'<a href="%1$s" class="custom-logo-link" rel="home">%2$s</a>', |
| 40 |
esc_url( home_url( '/' ) ), |
| 41 |
wp_get_attachment_image( $custom_logo_transparent_id, 'full', false, $custom_logo_attr ) |
| 42 |
); |
| 43 |
} |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
return $html; |
| 48 |
} |
| 49 |
add_filter( 'get_custom_logo', 'twentig_logo_transparent' ); |
| 50 |
|
| 51 |
/** |
| 52 |
* Hide the tagline by returning an empty string. |
| 53 |
*/ |
| 54 |
function twentig_hide_tagline( $html ) { |
| 55 |
if ( ! get_theme_mod( 'twentig_header_tagline', true ) ) { |
| 56 |
return ''; |
| 57 |
} |
| 58 |
return $html; |
| 59 |
} |
| 60 |
add_filter( 'twentytwenty_site_description', 'twentig_hide_tagline' ); |
| 61 |
|
| 62 |
/** |
| 63 |
* Determines if social icons should be displayed in the location. |
| 64 |
*/ |
| 65 |
function twentig_is_socials_location( $location ) { |
| 66 |
$locations = get_theme_mod( 'twentig_socials_location', array( 'modal-desktop', 'modal-mobile', 'footer' ) ); |
| 67 |
return in_array( $location, $locations ); |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Adds social links in the primary menu. |
| 72 |
*/ |
| 73 |
function twentig_nav_menu_social_icons( $items, $args ) { |
| 74 |
if ( 'primary' === $args->theme_location && has_nav_menu( 'social' ) && twentig_is_socials_location( 'primary-menu' ) ) { |
| 75 |
$items = $items . '<li class="menu-item-socials"><ul class="social-menu reset-list-style social-icons fill-children-current-color">' . |
| 76 |
wp_nav_menu( |
| 77 |
array( |
| 78 |
'echo' => false, |
| 79 |
'theme_location' => 'social', |
| 80 |
'container' => '', |
| 81 |
'container_class' => '', |
| 82 |
'items_wrap' => '%3$s', |
| 83 |
'menu_id' => '', |
| 84 |
'menu_class' => '', |
| 85 |
'depth' => 1, |
| 86 |
'link_before' => '<span class="screen-reader-text">', |
| 87 |
'link_after' => '</span>', |
| 88 |
'fallback_cb' => '', |
| 89 |
) |
| 90 |
) . '</ul></li>'; |
| 91 |
|
| 92 |
} |
| 93 |
|
| 94 |
return $items; |
| 95 |
} |
| 96 |
add_filter( 'wp_nav_menu_items', 'twentig_nav_menu_social_icons', 20, 2 ); |
| 97 |
|
| 98 |
/** |
| 99 |
* Disable the social icons menu inside the modal menu depending on the Customizer setting. |
| 100 |
*/ |
| 101 |
function twentig_modal_menu() { |
| 102 |
remove_filter( 'wp_nav_menu_items', 'twentig_nav_menu_social_icons', 20 ); |
| 103 |
if ( ! twentig_is_socials_location( 'modal-mobile' ) && ! twentig_is_socials_location( 'modal-desktop' ) ) { |
| 104 |
add_filter( 'has_nav_menu', 'twentig_disable_socials', 10, 2 ); |
| 105 |
} |
| 106 |
} |
| 107 |
add_action( 'get_template_part_template-parts/modal-menu', 'twentig_modal_menu', 10, 2 ); |
| 108 |
|
| 109 |
/** |
| 110 |
* Disable social icons menu for a given location. |
| 111 |
*/ |
| 112 |
function twentig_disable_socials( $has_nav_menu, $location ) { |
| 113 |
if ( 'social' === $location ) { |
| 114 |
return false; |
| 115 |
} |
| 116 |
return $has_nav_menu; |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* Add support for excerpt to page. |
| 121 |
*/ |
| 122 |
function twentig_support_page_excerpt() { |
| 123 |
add_post_type_support( 'page', 'excerpt' ); |
| 124 |
} |
| 125 |
add_action( 'init', 'twentig_support_page_excerpt' ); |
| 126 |
|
| 127 |
/** |
| 128 |
* Set template for page cover with excerpt. |
| 129 |
*/ |
| 130 |
function twentig_page_cover_excerpt( $template ) { |
| 131 |
if ( is_page_template( 'templates/template-cover.php' ) && is_page() && has_excerpt() ) { |
| 132 |
return TWENTIG_PATH . 'inc/twentytwenty/templates/template-cover.php'; |
| 133 |
} |
| 134 |
return $template; |
| 135 |
} |
| 136 |
add_filter( 'template_include', 'twentig_page_cover_excerpt' ); |
| 137 |
|