Your IP : 216.73.216.1
<?php
/**
* pally functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package pally
*/
if ( ! defined( 'pally_VERSION' ) ) {
// Replace the version number of the theme on each release.
define( 'pally_VERSION', '1.7' );
}
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
function pally_content_width() {
// This variable is intended to be overruled from themes.
$GLOBALS['content_width'] = apply_filters( 'pally_content_width', 640 );
}
add_action( 'after_setup_theme', 'pally_content_width', 0 );
// Overwrite rss2-feed with the file in the theme folder.
function custom_rss() {
get_template_part( 'feed', 'rss2' );
}
remove_all_actions( 'do_feed_rss2' );
add_action( 'do_feed_rss2', 'custom_rss', 10, 1 );
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function pally_widgets_init() {
register_sidebar(
array(
'name' => esc_html__( 'Sidebar', 'pally' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Add widgets here.', 'pally' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
add_action( 'widgets_init', 'pally_widgets_init' );
/**
* Enqueue scripts and styles.
*/
function pally_scripts() {
wp_enqueue_script( 'pally_main-script', get_theme_file_uri() . '/assets/static/js/main.js', array(), '1.0.0', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'pally_comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'pally_scripts' );
function pally_styles() {
wp_enqueue_style( 'pally_main-style', get_theme_file_uri() . '/assets/static/css/main.css' );
}
add_action( 'wp_enqueue_scripts', 'pally_styles' );
/**
* Change html output for comment title_reply for a11y reasons (was h3)
**/
function pally_custom_reply_title( $defaults ){
$defaults['title_reply_before'] = '<h2 id="reply-title" class="comment-reply-title">';
$defaults['title_reply_after'] = '</h2>';
return $defaults;
}
add_filter( 'comment_form_defaults', 'pally_custom_reply_title' );
/**
* Custom template tags for this theme.
*/
require get_theme_file_path('/inc/template-tags.php');
/**
* Functions which enhance the theme by hooking into WordPress.
*/
require get_theme_file_path('/inc/template-functions.php');
/**
* Custom Comment Walker template.
*/
require get_theme_file_path('/classes/class-ally-walker-comment.php');
/**
* Add Gutenberg-Blocks.
*/
require_once get_theme_file_path('/assets/blocks/setup-blocks.php');
/**
* Customizer additions.
*/
require_once get_theme_file_path('/inc/setup.php');
/**
* Load Jetpack compatibility file.
*/
if ( defined( 'JETPACK__VERSION' ) ) {
require get_theme_file_path('/inc/jetpack.php');
}
function pally_wporg_fcs_excerpt_more( $more ) {
return '';
}
add_filter( 'excerpt_more', 'pally_wporg_fcs_excerpt_more' );
/**
* Filter the "read more" excerpt string link to the post.
*
* @param string $more "Read more" excerpt string.
* @return string (Maybe) modified "read more" excerpt string.
*/
/*function pally_wpdocs_excerpt_more( $more ) {
if ( ! is_single() ) {
$more = sprintf( '<a class="read-more" href="%1$s">%2$s <span class="screen-reader-text">%3$s</span></a>',
get_permalink( get_the_ID() ),
__( 'Read more', 'pally' ),
get_the_title ()
);
}
return $more;
}
add_filter( 'excerpt_more', 'pally_wpdocs_excerpt_more' );
*/
/**
* Function for Extra A11y Page in Admin menu
*/
function pally_admin_menu() {
add_menu_page(
__( 'Accessibility Tips', 'pally' ),
__( 'About & A11y Tips', 'pally' ),
'edit_posts',
'a11y',
'pally_admin_page_a11y',
'dashicons-warning',
3
);
}
add_action( 'admin_menu', 'pally_admin_menu' );
function pally_admin_style() {
wp_enqueue_style( 'pally_admin-style', get_stylesheet_directory_uri() . '/assets/admin/admin-style-a11y.css' );
}
add_action( 'admin_enqueue_scripts', 'pally_admin_style');
//remove website field at comment form
function pally_remove_website_field($fields) {
unset($fields['url']);
unset($fields['cookies']);
return $fields;
}
add_filter('comment_form_default_fields', 'pally_remove_website_field');
//Remove role="navigation" from post-navigation
function pally_post_navigation_template( $template ) {
$template = '
<nav class="navigation %1$s" aria-label="'. esc_html__( 'Post navigation', 'pally' ) .'">
<div class="nav-links">%3$s</div>
</nav>';
return $template;
}
add_filter( 'navigation_markup_template', 'pally_post_navigation_template' );
//Remove frameborder for iframes
function pally_kill_frameborder( $html ) {
return str_replace( 'frameborder="0"', "", $html );
}
add_filter('embed_oembed_html', 'pally_kill_frameborder', 10, 3);
//Remove cancel-comment
function pally_remove_comment_reply_link($link) {
return '';
}
add_filter('cancel_comment_reply_link', 'pally_remove_comment_reply_link' );
//Create cancel comment reply link
function pally_create_cancel_button($post_id) {
remove_filter('cancel_comment_reply_link', 'pally_remove_comment_reply_link');
cancel_comment_reply_link(__( 'Cancel', 'pally' ));
}
add_action( 'comment_form', 'pally_create_cancel_button');
//Get rid of self-closing tags
if ( !is_admin() && ( ! defined('DOING_AJAX') || ( defined('DOING_AJAX') && ! DOING_AJAX ) ) ) {
ob_start( 'pally_html5_slash_fixer' );
add_action( 'shutdown', 'pally_html5_slash_fixer_flush' );
}
function pally_html5_slash_fixer( $buffer ) {
return str_replace( ' />', '>', $buffer );
}
function pally_html5_slash_fixer_flush() {
if(ob_get_length() > 0) ob_end_flush();
}
add_action('after_setup_theme', function() {
// Remove SVG
remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' );
// Remove duotones
remove_filter('render_block', 'wp_render_duotone_support');
});
// breadcrumb
function pally_nav_breadcrumb() {
$delimiter = '/';
$home = 'Home';
$before = '<span class="current-page">';
$after = '</span>';
if ( !is_home() && !is_front_page() || is_paged() ) {
echo '<nav class="pally-breadcrumbs">'. esc_html__( 'You are here:', 'pally' ) .' ';
global $post;
$homeLink = home_url();
echo '<a href="' . $homeLink . '">' . $home . '</a> ' . $delimiter . ' ';
if ( is_home() && is_paged() ) {
echo '<a href="' . esc_url(get_post_type_archive_link('post')) . '">' . "Blog" .'</a> ' . $delimiter .' ' . esc_html__( 'Page', 'pally' ) . ' ';
}
if ( is_category()) {
global $wp_query;
$cat_obj = $wp_query->get_queried_object();
$thisCat = $cat_obj->term_id;
$thisCat = get_category($thisCat);
$parentCat = get_category($thisCat->parent);
if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
echo $before . single_cat_title('', false) . $after;
} elseif ( is_day() ) {
echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
echo $before . get_the_time('d') . $after;
} elseif ( is_month() ) {
echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
echo $before . get_the_time('F') . $after;
} elseif ( is_year() ) {
echo $before . get_the_time('Y') . $after;
} elseif ( is_single() && !is_attachment() ) {
if ( get_post_type() != 'post' ) {
$post_type = get_post_type_object(get_post_type());
$slug = $post_type->rewrite;
echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a> ' . $delimiter . ' ';
echo $before . get_the_title() . $after;
} else {
$cat = get_the_category(); $cat = $cat[0];
echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
echo $before . get_the_title() . $after;
}
} elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
echo $before . ''. esc_html__( 'Your search results for', 'pally' ) .' "' . get_search_query() . '"' . $after;
} elseif ( is_attachment() ) {
$parent = get_post($post->post_parent);
$cat = get_the_category($parent->ID); $cat = $cat[0];
echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . ' ';
echo $before . get_the_title() . $after;
} elseif ( is_page() && !$post->post_parent ) {
echo $before . get_the_title() . $after;
} elseif ( is_page() && $post->post_parent ) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
echo $before . get_the_title() . $after;
} elseif ( is_search() ) {
echo $before . ''. esc_html__( 'Your search results for', 'pally' ) .' "' . get_search_query() . '"' . $after;
} elseif ( is_tag() ) {
echo $before . ''. esc_html__( 'Posts with tag', 'pally' ) .' "' . single_tag_title('', false) . '"' . $after;
} elseif ( is_404() ) {
echo $before . ''. esc_html__( '404 Page not found', 'pally' ) .' ' . $after;
} elseif ( is_author() ) {
echo $before . ''. esc_html__( 'About the author', 'pally' ) .' ' . $after;
}
if ( get_query_var('paged') ) {
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' ';
echo get_query_var('paged');
}
echo '</nav>';
}
}