2019-05-23 12:30:31 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This file adds functions and actions for classes.
|
|
|
|
*
|
2021-07-09 15:43:11 -04:00
|
|
|
* @author Adam Piontek
|
2019-05-23 12:30:31 -04:00
|
|
|
* @since 1.0.0
|
|
|
|
*/
|
|
|
|
|
2021-07-02 10:24:48 -04:00
|
|
|
namespace WP_73k;
|
2019-05-23 12:30:31 -04:00
|
|
|
|
|
|
|
add_filter( 'body_class', function( $classes ) {
|
|
|
|
|
2021-07-04 18:16:33 -04:00
|
|
|
if ( is_singular( ['post', 'page'] ) ) {
|
|
|
|
$classes[] = 'singular';
|
|
|
|
}
|
2019-05-23 12:30:31 -04:00
|
|
|
|
2021-07-04 18:16:33 -04:00
|
|
|
if ( is_front_page() ) {
|
|
|
|
$classes[] = 'front-page';
|
|
|
|
}
|
2019-05-23 12:30:31 -04:00
|
|
|
|
2021-07-04 18:16:33 -04:00
|
|
|
return $classes;
|
2019-05-23 12:30:31 -04:00
|
|
|
|
2021-07-04 18:16:33 -04:00
|
|
|
});
|
|
|
|
|
2021-07-09 12:20:38 -04:00
|
|
|
/**
|
2021-07-04 18:16:33 -04:00
|
|
|
* Filter to add CSS class to navbar menu <li> items
|
|
|
|
*/
|
|
|
|
add_filter( 'nav_menu_css_class' , function( $classes, $item, $args, $depth ) {
|
|
|
|
if ( 'primary' === $args->theme_location ) {
|
|
|
|
if (property_exists($args, 'menu_item_class')) {
|
|
|
|
array_push($classes, $args->menu_item_class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $classes;
|
|
|
|
}, 3, 4 );
|
|
|
|
|
2021-07-09 12:20:38 -04:00
|
|
|
/**
|
2021-07-04 18:16:33 -04:00
|
|
|
* Filter to add CSS class to navbar menu item <a> links
|
|
|
|
*/
|
|
|
|
add_filter( 'nav_menu_link_attributes' , function( $atts, $item, $args ) {
|
|
|
|
if ( 'primary' === $args->theme_location ) {
|
|
|
|
$atts['class'] = (empty($atts['class'])) ? '' : $atts['class'];
|
|
|
|
if ( in_array('current_page_item', $item->classes) ) {
|
|
|
|
$atts['class'] .= ' active';
|
|
|
|
}
|
|
|
|
if (property_exists($args, 'link_class')) {
|
|
|
|
$atts['class'] .= ' ' . $args->link_class;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $atts;
|
|
|
|
}, 2, 3 );
|
|
|
|
|
2021-07-09 12:20:38 -04:00
|
|
|
/**
|
2021-07-04 18:16:33 -04:00
|
|
|
* Filter to add icons to navbar menu items
|
|
|
|
*/
|
|
|
|
add_filter( 'wp_nav_menu_objects', function($items, $args) {
|
|
|
|
$svgicon_prefix = 'icon-';
|
|
|
|
foreach ( $items as $k => $object ) {
|
|
|
|
foreach ($object->classes as $c) {
|
|
|
|
if (substr( $c, 0, strlen( $svgicon_prefix ) ) === $svgicon_prefix) {
|
|
|
|
$icon_slug = str_replace($svgicon_prefix, '', $c);
|
2021-07-26 11:03:32 -04:00
|
|
|
$object->title = inline_svg( $icon_slug, array( 'div_class' => 'icon baseline' ) ) . "\\" . $object->title;
|
2021-07-04 18:16:33 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $items;
|
2021-07-07 13:07:19 -04:00
|
|
|
}, 1, 2 );
|
2021-07-08 11:49:18 -04:00
|
|
|
|
2021-07-09 12:20:38 -04:00
|
|
|
/**
|
2021-07-10 10:24:05 -04:00
|
|
|
* Filter to remove syntax-highlighting-code-block plugin styles from frontend
|
2021-07-08 11:49:18 -04:00
|
|
|
*/
|
2021-07-10 10:24:05 -04:00
|
|
|
add_filter('syntax_highlighting_code_block_styling', '__return_false');
|
2021-07-09 12:20:38 -04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set document title (in html head) to be reversed with '\' separator
|
|
|
|
*/
|
|
|
|
add_filter( 'document_title_separator', function ( $separator ) {
|
|
|
|
return '\\';
|
|
|
|
} );
|
|
|
|
add_filter('document_title_parts', function ($title) {
|
|
|
|
return (is_home() || is_front_page()) ? $title : array_reverse($title);
|
2021-07-10 17:13:24 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Exclude pages from WordPress Search
|
|
|
|
*/
|
|
|
|
if (!is_admin()) {
|
|
|
|
add_filter('pre_get_posts',function($query) {
|
|
|
|
if ($query->is_search) {
|
|
|
|
$query->set('post_type', 'post');
|
|
|
|
}
|
|
|
|
return $query;
|
|
|
|
});
|
|
|
|
}
|