diff options
Diffstat (limited to 'functions.php')
| -rw-r--r-- | functions.php | 243 |
1 files changed, 243 insertions, 0 deletions
diff --git a/functions.php b/functions.php new file mode 100644 index 0000000..eb5f9f3 --- /dev/null +++ b/functions.php @@ -0,0 +1,243 @@ +<?php +/** + * Understrap functions and definitions + * + * @package understrap + */ + +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly. +} + +/** + * Initialize theme default settings + */ +require get_template_directory() . '/inc/theme-settings.php'; + +/** + * Theme setup and custom theme supports. + */ +require get_template_directory() . '/inc/setup.php'; + +/** + * Register widget area. + */ +require get_template_directory() . '/inc/widgets.php'; + +/** + * Enqueue scripts and styles. + */ +require get_template_directory() . '/inc/enqueue.php'; + +/** + * Custom template tags for this theme. + */ +require get_template_directory() . '/inc/template-tags.php'; + +/** + * Custom pagination for this theme. + */ +require get_template_directory() . '/inc/pagination.php'; + +/** + * Custom hooks. + */ +require get_template_directory() . '/inc/hooks.php'; + +/** + * Custom functions that act independently of the theme templates. + */ +require get_template_directory() . '/inc/extras.php'; + +/** + * Customizer additions. + */ +require get_template_directory() . '/inc/customizer.php'; + +/** + * Custom Comments file. + */ +require get_template_directory() . '/inc/custom-comments.php'; + +/** + * Load Jetpack compatibility file. + */ +require get_template_directory() . '/inc/jetpack.php'; + +/** + * Load custom WordPress nav walker. + */ +require get_template_directory() . '/inc/class-wp-bootstrap-navwalker.php'; + +/** + * Load WooCommerce functions. + */ +require get_template_directory() . '/inc/woocommerce.php'; + +/** + * Load Editor functions. + */ +require get_template_directory() . '/inc/editor.php'; + +/** + * # Modified + */ + +/** + * Load custom taxonomies. + */ +require get_template_directory() . '/taxonomy.php'; + +/** + * Removes "Tag:" and "Category:" from archive pages. + */ +add_filter('get_the_archive_title', function ($title) { + if ( is_category() ) { + $title = single_cat_title( '', false ); + } elseif ( is_tag() ) { + $title = single_tag_title( '', false ); + } + return $title; +}); + +/** + * Delays RSS-Feed by 60 minutes. + */ +function Delay_RSS_After_Publish($where) { + global $wpdb; + if (is_feed()) { + $now = gmdate('Y-m-d H:i:s'); + $wait = '60'; + $device = 'MINUTE'; + $where.=" AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait "; + } + return $where; +} +add_filter('posts_where', 'Delay_RSS_After_Publish'); + +/** + * Deaktiviert REST-API und entfernt die Header aus dem HTML. + */ +add_filter('rest_enabled', '_return_false'); +add_filter('rest_jsonp_enabled', '_return_false'); +remove_action( 'wp_head', 'rest_output_link_wp_head', 10 ); +remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 ); + +/** + * Entfernt wlwmanifest.xml (Microsoft Live Writer) + */ +remove_action('wp_head', 'wlwmanifest_link'); +remove_action('wp_head', 'rsd_link'); + +/** + * Disable W3TC footer comment for everyone but Admins (single site & network mode) + */ +if ( !current_user_can( 'activate_plugins' ) ) { + add_filter( 'w3tc_can_print_comment', function( $w3tc_setting ) { return false; }, 10, 1 ); +} + +/** + * Add short code functionality to excerpts. + */ +add_filter( 'the_excerpt', 'shortcode_unautop'); +add_filter( 'the_excerpt', 'do_shortcode'); + +/** + * Adds short code: [glossar "Term"] + */ +function print_glossar_link( $atts ) { + if ( count($atts) == 2 ) { + $linktext = $atts[1]; + } else { + $linktext = $atts[0]; + } + return '<a class="glossar-link" href="https://www.fuselkoenig.de/glossar/#' . htmlentities($atts[0]) . '" title="Im Glossar zu ' . htmlentities($atts[0]) . '">' . htmlentities($linktext) . '</a>'; +} +add_shortcode( "glossar", "print_glossar_link" ); + +/** + * Unsure if needed. +function wpsites_attachment_redirect(){ + global $post; + if ( is_attachment() && isset($post->post_parent) && is_numeric($post->post_parent) && ($post->post_parent != 0) ) { + + wp_redirect( get_permalink( $post->post_parent ), 301 ); + exit(); + wp_reset_postdata(); + } +} +*/ + +/** + * Remove tags from tag cloud with zero entries. + */ +function set_widget_tag_cloud_excluded_tags($args){ + $min_count = 1; + if ( "brennerei" == $args['taxonomy'] ) { + $min_count+=1; + } + $excluded_tags=get_tags_termid_to_exclude($args['taxonomy'], $min_count); + $my_args = array( 'exclude'=>$excluded_tags ); + $args = wp_parse_args( $args, $my_args ); + return $args; +} +function get_tags_termid_to_exclude($taxonomy, $max_excluded_count_value){ + $term_ids = array(); + foreach ( + get_terms( array( + 'taxonomy' => $taxonomy, + 'hide_empty' => true) ) + as $category ) + { + if ($category->count < $max_excluded_count_value ){ + $term_ids[]=$category->term_id; + } + } + return $term_ids; +} +add_filter( 'widget_tag_cloud_args', 'set_widget_tag_cloud_excluded_tags' ); + +/** + * Add Matomo support to tag cloud links. + */ +function modify_tag_cloud_add_piwik_class($args) { + $start_s = '<a href="https://www.fuselkoenig.de/brennerei/'; + if ( $start_s === substr( $args, 0, strlen($start_s) ) ) { + $args = str_replace('class="', 'class="pwk-tc-brennerei ', $args); + } else { + $args = str_replace('class="', 'class="pwk-tc-category ', $args); + } + #file_put_contents("/tmp/wp.tagcloud.txt", ($args) ); + return $args; +} +add_filter( 'wp_tag_cloud', 'modify_tag_cloud_add_piwik_class' ); + +/** + * Hides the checkbox to save name and email when someone comments. + */ +function comment_form_hide_cookies_consent( $fields ) { + unset( $fields['cookies'] ); + return $fields; +} +add_filter( 'comment_form_default_fields', 'comment_form_hide_cookies_consent' ); + +/** + * Function to get the clean title of a blog post. + */ +if ( ! function_exists("get_my_clean_title")) { + + function get_my_clean_title( $title ) { + $orig_title = str_replace('Im Test: ', '', $title); + /* + * Entfernt alles, was in den Klammern steht. + */ + $my_title = preg_replace("/\(.+\)/i", "", $orig_title); + + if ( is_null($my_title) ) { + return trim($orig_title); + } else { + return trim($my_title); + } + } + +} |
