/*
Theme Name:     Newspaper Child theme
Theme URI: 		http://themeforest.net/user/tagDiv/portfolio
Description:    Child theme made by tagDiv
Author:         tagDiv
Author URI: 	http://themeforest.net/user/tagDiv/portfolio
Template:       Newspaper
Version:        9.0c
*/


/*  ----------------------------------------------------------------------------
    This file will load automatically when the child theme is active. You can use it
    for custom CSS.
*/

// Deregister Contact Form 7 JavaScript files on all pages without a form
add_action( 'wp_print_scripts', 'aa_deregister_javascript', 100 );
function aa_deregister_javascript() {
    if ( ! is_page( 'contact-us' ) ) {
        wp_deregister_script( 'contact-form-7' );
    }
}

/**
 * Add defer attribute to Google reCaptcha script
 *
 * @param String $tag		- Script HTML
 * @param String $handle	- Unique identifier for script
 *
 * @return String $tag
 */
function prefix_add_defer_attribute( $tag, $handle ) {
	
	// The handle for our google recaptcha script is <code>google-recaptcha</code>
	// IF it's not this handle return early
	if( 'google-recaptcha' !== $handle ) {
		return $tag;
	}
	
	// IF we don't already have a defer attribute, add it
	if( false === strpos( $tag, 'defer ' ) && false === strpos( $tag, ' defer' ) ) {
		$tag = str_replace( 'src=', 'defer src=', $tag );
	}
	
	return $tag;
	
}
add_filter( 'script_loader_tag', 'prefix_add_defer_attribute', 10, 2 );

// Removing Emojis

add_action( 'init', 'infophilic_disable_wp_emojicons' );
function infophilic_disable_wp_emojicons() 
{
    // all actions related to emojis

    remove_action( 'admin_print_styles', 'print_emoji_styles' );
    remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
    remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
    remove_action( 'wp_print_styles', 'print_emoji_styles' );
    remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
    remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
    remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
}

// Remove WP embed script

function infophilic_stop_loading_wp_embed() {
   if (!is_admin()) {
      wp_deregister_script('wp-embed');
}
}
add_action('init', 'infophilic_stop_loading_wp_embed');

// Preload Newspaper fonts for responsive theme (main theme)

function dns_prefetch_responsive() {
	
	echo "<link href='https://www.celtica.es/wp-content/themes/Newspaper/images/icons/newspaper.woff?19' rel='preload' as='font' type='font/woff' crossorigin>";
}
add_action( 'wp_head', 'dns_prefetch_responsive', 0 );