File: D:/HostingSpaces/MDalebout3/prdct.nl/wwwroot/wp-content/themes/theme/functions.php
<?php
// inc
require_once 'blocks/blocks.php';
add_post_type_support( 'page', 'excerpt' );
add_action( 'after_setup_theme', 'prdct_setup' );
function prdct_setup() {
load_theme_textdomain( 'prdct', get_template_directory() . '/languages' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'html5', array( 'search-form' ) );
register_nav_menus( array( 'main-menu' => esc_html__( 'Main Menu', 'prdct' ) ) );
register_nav_menus( array( 'quick-access' => esc_html__( 'Quick Access Menu', 'prdct' ) ) );
register_nav_menus( array( 'footer-menu' => esc_html__( 'Footer Menu', 'prdct' ) ) );
}
add_action( 'wp_enqueue_scripts', 'prdct_load_scripts' );
function prdct_load_scripts() {
wp_enqueue_style( 'owl', '/src/css/owl.carousel.min.css' );
wp_enqueue_style( 'owl-theme', '/src/css/owl.theme.default.css' );
wp_enqueue_style( 'prdct-style', '/src/css/css.css' );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'main' ,'/src/js/scripts.js');
}
add_action( 'wp_footer', 'prdct_footer_scripts' );
function prdct_footer_scripts() {
?>
<script>
jQuery(document).ready(function ($) {
var deviceAgent = navigator.userAgent.toLowerCase();
if (deviceAgent.match(/(iphone|ipod|ipad)/)) {
$("html").addClass("ios");
$("html").addClass("mobile");
}
if (navigator.userAgent.search("MSIE") >= 0) {
$("html").addClass("ie");
}
else if (navigator.userAgent.search("Chrome") >= 0) {
$("html").addClass("chrome");
}
else if (navigator.userAgent.search("Firefox") >= 0) {
$("html").addClass("firefox");
}
else if (navigator.userAgent.search("Safari") >= 0 && navigator.userAgent.search("Chrome") < 0) {
$("html").addClass("safari");
}
else if (navigator.userAgent.search("Opera") >= 0) {
$("html").addClass("opera");
}
});
</script>
<?php
}
function displaySVG($link) {
// $link = str_replace('http://','https://',$link);
$link = str_replace(get_site_url(),'',$link);
$svgPath = $_SERVER['DOCUMENT_ROOT'].$link;
$svg = file_get_contents($svgPath);
echo fixSVGStyles($svg);
}
function add_file_types_to_uploads($file_types){
$new_filetypes = array();
$new_filetypes['svg'] = 'image/svg+xml';
$new_filetypes['js'] = 'application/javascript';
$file_types = array_merge($file_types, $new_filetypes );
return $file_types;
}
add_filter('upload_mimes', 'add_file_types_to_uploads');
function fixSVGstyles ($svg) {
$time = time();
$svg = str_replace('.a','.a'.$time, $svg);
$svg = str_replace('.b','.b'.$time, $svg);
$svg = str_replace('.c','.c'.$time, $svg);
$svg = str_replace('.d','.d'.$time, $svg);
$svg = str_replace('.e','.e'.$time, $svg);
$svg = str_replace('.f','.f'.$time, $svg);
$svg = str_replace('.g','.g'.$time, $svg);
$svg = str_replace('.h','.h'.$time, $svg);
$svg = str_replace('.i','.i'.$time, $svg);
$svg = str_replace('.j','.j'.$time, $svg);
$svg = str_replace('.k','.k'.$time, $svg);
$svg = str_replace('.l','.l'.$time, $svg);
$svg = str_replace('.m','.m'.$time, $svg);
$svg = str_replace('.n','.n'.$time, $svg);
$svg = str_replace('.o','.o'.$time, $svg);
$svg = str_replace('.p','.p'.$time, $svg);
$svg = str_replace('.q','.q'.$time, $svg);
$svg = str_replace('.r','.r'.$time, $svg);
$svg = str_replace('.s','.s'.$time, $svg);
$svg = str_replace('.t','.t'.$time, $svg);
$svg = str_replace('.u','.u'.$time, $svg);
$svg = str_replace('.v','.v'.$time, $svg);
$svg = str_replace('.w','.w'.$time, $svg);
$svg = str_replace('.x','.x'.$time, $svg);
$svg = str_replace('.y','.y'.$time, $svg);
$svg = str_replace('.z','.z'.$time, $svg);
$svg = str_replace('#a','#a'.$time, $svg);
$svg = str_replace('#b','#b'.$time, $svg);
$svg = str_replace('#c','#c'.$time, $svg);
$svg = str_replace('#d','#d'.$time, $svg);
$svg = str_replace('#e','#e'.$time, $svg);
$svg = str_replace('#f','#f'.$time, $svg);
$svg = str_replace('#g','#g'.$time, $svg);
$svg = str_replace('#h','#h'.$time, $svg);
$svg = str_replace('#i','#i'.$time, $svg);
$svg = str_replace('#j','#j'.$time, $svg);
$svg = str_replace('#k','#k'.$time, $svg);
$svg = str_replace('#l','#l'.$time, $svg);
$svg = str_replace('#m','#m'.$time, $svg);
$svg = str_replace('#n','#n'.$time, $svg);
$svg = str_replace('#o','#o'.$time, $svg);
$svg = str_replace('#p','#p'.$time, $svg);
$svg = str_replace('#q','#q'.$time, $svg);
$svg = str_replace('#r','#r'.$time, $svg);
$svg = str_replace('#s','#s'.$time, $svg);
$svg = str_replace('#t','#t'.$time, $svg);
$svg = str_replace('#u','#u'.$time, $svg);
$svg = str_replace('#v','#v'.$time, $svg);
$svg = str_replace('#w','#w'.$time, $svg);
$svg = str_replace('#x','#x'.$time, $svg);
$svg = str_replace('#y','#y'.$time, $svg);
$svg = str_replace('#z','#z'.$time, $svg);
$svg = str_replace('class="a','class="a'.$time, $svg);
$svg = str_replace('class="b','class="b'.$time, $svg);
$svg = str_replace('class="c','class="c'.$time, $svg);
$svg = str_replace('class="d','class="d'.$time, $svg);
$svg = str_replace('class="e','class="e'.$time, $svg);
$svg = str_replace('class="f','class="f'.$time, $svg);
$svg = str_replace('class="g','class="g'.$time, $svg);
$svg = str_replace('class="h','class="h'.$time, $svg);
$svg = str_replace('class="i','class="i'.$time, $svg);
$svg = str_replace('class="j','class="j'.$time, $svg);
$svg = str_replace('class="k','class="k'.$time, $svg);
$svg = str_replace('class="l','class="l'.$time, $svg);
$svg = str_replace('class="m','class="m'.$time, $svg);
$svg = str_replace('class="n','class="n'.$time, $svg);
$svg = str_replace('class="o','class="o'.$time, $svg);
$svg = str_replace('class="p','class="p'.$time, $svg);
$svg = str_replace('class="q','class="q'.$time, $svg);
$svg = str_replace('class="r','class="r'.$time, $svg);
$svg = str_replace('class="s','class="s'.$time, $svg);
$svg = str_replace('class="t','class="t'.$time, $svg);
$svg = str_replace('class="u','class="u'.$time, $svg);
$svg = str_replace('class="v','class="v'.$time, $svg);
$svg = str_replace('class="w','class="w'.$time, $svg);
$svg = str_replace('class="x','class="x'.$time, $svg);
$svg = str_replace('class="y','class="y'.$time, $svg);
$svg = str_replace('class="z','class="z'.$time, $svg);
return $svg;
}
function move_admin_bar() {
echo '
<style type="text/css">
body {margin-top: 0;padding-bottom: 28px;}
body.admin-bar #wphead {padding-top: 0;}
body.admin-bar #footer {padding-bottom: 28px;}
#wpadminbar { top: auto !important;bottom: 0;}
#wpadminbar .quicklinks .menupop ul { bottom: 28px;}
</style>';
}
add_action( 'wp_head', 'move_admin_bar' );
function encode_email($e) {
$output = '';
for ($i = 0; $i < strlen($e); $i++) { $output .= '&#'.ord($e[$i]).';'; }
return $output;
}
add_shortcode( 'mailto', 'mailto_func' );
function mailto_func( $atts ) {
$mailto = encode_email('mailto:'.$atts['email']);
return '<a href="'.$mailto.'">'.encode_email($atts['email']).'</a>';
}
add_action('get_header', 'my_filter_head');
function my_filter_head() {
remove_action('wp_head', '_admin_bar_bump_cb');
}
// Method 2: Setting.
function mapkey_acf_init() {
acf_update_setting('google_api_key', 'AIzaSyCYAFxSuYOBXW_hm_7t1BcUOjnoRG0uZY0');
//acf_update_setting('google_api_key', 'AIzaSyC7PDGVogV7Z9fABZiI14njCC6sgTd4OcY');
}
add_action('acf/init', 'mapkey_acf_init');
function underscoreTitle($title){
$title = strtolower($title);
return '_'.$title;
}
function display_bredcrumbs() {
global $post;
if (is_singular('post')) {
$posts_home_id = apply_filters( 'wpml_object_id', 850, 'post' );
$page_home = get_post($posts_home_id);
$page_parent_id = apply_filters( 'wpml_object_id',$page_home->post_parent, 'post' );;
$page_root = get_post($page_parent_id);
//build html
// root
$html = '<nav class="breadcrumbs">';
$html .= '<a class="breadcrumb-item" href="'.get_page_link($page_parent_id).'" title="'.$page_root->post_title.'">'.underscoreTitle($page_root->post_title).'</a>';
$html .= ' / ';
// posts home
$html .= '<a class="breadcrumb-item" href="'.get_page_link($posts_home_id).'" title="'.$page_home->post_title.'">'.underscoreTitle($page_home->post_title).'</a>';
$html .= ' / ';
$html .= '<span class="breadcrumb-item" href="'.get_the_permalink($post->ID).'" title="'.$post->post_title.'">'.underscoreTitle($post->post_title).'</span>';
$html .= '</nav>';
} else {
if ($post->post_parent != "") {
$html = '<nav class="breadcrumbs-page">';
$page_parent_id = apply_filters( 'wpml_object_id',$post->post_parent, 'post' );;
$page_root = get_post($page_parent_id);
$html .= '<a class="breadcrumb-item" href="'.get_page_link($page_parent_id).'" title="'.$page_root->post_title.'">'.underscoreTitle($page_root->post_title).'</a>';
$html .= ' / ';
// posts home
$html .= '<span class="breadcrumb-item" href="'.get_page_link($post->ID).'" title="'.$post->post_title.'">'.underscoreTitle($post->post_title).'</span>';
$html .= '</nav>';
} else {
$html = '';
}
}
echo $html;
}