How can we help?

If you are looking for support for our Poka theme, this is the place!

Home Forums Poka v2 support Move script from header to footer and increase loading speed

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by  duendecasino@gmail.com 3 weeks, 1 day ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #2216

    Hi guys! I would like to share with you the modifications I have made on my website:Casinos Fortune
    These modifications move the header script to the footer and other modifications that increase the loading speed of the website
    Just add this code in the functions.php file of your theme. So that it remains permanent, I have it installed poka_v2_child, where I make modifications.

    <?php
    // =============================================================================
    // Your functions
    // =============================================================================
    
    // Disable WordPress Heartbeat
    add_action('init', 'stop_heartbeat', 1);
    function stop_heartbeat() {
     wp_deregister_script('heartbeat');
    }
    
    function poka_dequeue_parent_styles() {
        wp_dequeue_style( 'poka-vendor-styles' );
        wp_deregister_style( 'poka-vendor-styles' );
        
        wp_dequeue_style( 'poka-main-styles' );
        wp_deregister_style( 'poka-main-styles' );    
    }
    add_action( 'wp_print_styles', 'poka_dequeue_parent_styles' );
    
    function poka_child_enqueue_styles() {
        //First vendor styles
        wp_enqueue_style( 'vendor-theme-style', get_template_directory_uri() . '/css/styles-vendor.css', array( 'poka-fonts' ), wp_get_theme(get_template())->get('Version') );    
        
        //First parent styles
        wp_enqueue_style( 'parent-theme-style', get_template_directory_uri() . '/css/styles.css', array( 'poka-fonts', 'vendor-theme-style' ), wp_get_theme(get_template())->get('Version') );
        
        //Now the child styles
        wp_enqueue_style( 'child-theme-style', get_stylesheet_directory_uri() . '/style.css', array( 'poka-fonts', 'vendor-theme-style', 'parent-theme-style' ), wp_get_theme(get_template())->get('Version') );  
    }
    add_action( 'wp_enqueue_scripts', 'poka_child_enqueue_styles', 10 );
    
    function poka_child_init(){
            
        update_option( 'comment_registration', 0 );
        
    }
    
    add_action( 'init', 'poka_child_init' );
    
    add_filter('acf/settings/show_admin', '__return_true', 100);
    
    //Change CPT slug
    add_filter( 'register_post_type_args', 'change_slug_affiliates_cpt', 10, 2 );
    function change_slug_affiliates_cpt( $args, $post_type ) {
    
        if ( $post_type == 'affiliates') {
            $args['rewrite']['slug'] = 'reviews';
        }
    
        return $args;
    }
    
    //Change Review taxonomies
    add_filter( 'register_taxonomy_args', 'change_slug_affiliates_tax', 10, 2 );
    function change_slug_affiliates_tax( $args, $taxonomy ) {
    
        if ( $taxonomy == 'lists') {
            $args['rewrite']['slug'] = 'casinos';
        }
    
        return $args;
    }
    
    // Remove Query String
    function _remove_script_version( $src ){ 
    $parts = explode( '?', $src ); 	
    return $parts[0]; 
    } 
    add_filter( 'script_loader_src', '_remove_script_version', 15, 1 ); 
    add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );
    
    /**
     * Disable the emoji
    */
    function desactiva_emojis() {
       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_action( 'admin_print_styles', 'print_emoji_styles' );    
       remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
       remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );  
       remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
       add_filter( 'tiny_mce_plugins', 'desactiva_emojis_tinymce' );
    }
    add_action( 'init', 'desactiva_emojis' );
    /**
     * Filter that removes the emoji plugin from TinyMCE
     * @param    array  $plugins  
     * @return   array  Difference betwen the two arrays
    */
    function desactiva_emojis_tinymce( $plugins ) {
       if ( is_array( $plugins ) ) {
           return array_diff( $plugins, array( 'wpemoji' ) );
       } else {
           return array();
       }
    }
    
    // Custom upload mimes svg, webp
    add_filter( 'upload_mimes', 'custom_upload_mimes' );
    function custom_upload_mimes( $existing_mimes = array() ) {
    	// Add the file extension to the array
    	$existing_mimes['svg'] = 'image/svg+xml';
    	return $existing_mimes;
    }
    
    add_filter( 'mime_types', 'mycode_mime_types', 20 );
    function mycode_mime_types( $mime_types ) {
     
        if ( isset( $mime_types['webp'] ) ) {
            return $mime_types;
        }
     
        $mime_types['webp'] = 'image/webp';
     
        return $mime_types;
    }
    
    // Remove dashicons in frontend for unauthenticated users
    add_action( 'wp_enqueue_scripts', 'bs_dequeue_dashicons' );
    function bs_dequeue_dashicons() {
        if ( ! is_user_logged_in() ) {
            wp_deregister_style( 'dashicons' );
        }
    }
    
    //Loading jQuery in footer
    function jquery_enqueue() {
    
      wp_deregister_script('jquery');
      wp_register_script('jquery', "/wp-includes/js/jquery/jquery.js", false, '1.11.3', true);
      wp_enqueue_script('jquery');
    
    }
    
    if (!is_admin()) add_action("wp_enqueue_scripts", "jquery_enqueue", 11);
    
    // Remove RSDlink and wlwmanifest
    add_filter('the_generator', create_function('', 'return "";'));
    remove_action('wp_head', 'rsd_link');
    remove_action('wp_head', 'wlwmanifest_link');
    remove_action( 'wp_head', 'feed_links_extra', 3 );
    remove_action( 'wp_head', 'feed_links', 2 );
    remove_action( 'wp_head', 'index_rel_link'); // index link
    remove_action('wp_head','wp_oembed_add_discovery_links', 10 ); // Removes oembed discorvery link
    remove_action('wp_head','wp_oembed_add_host_js');
    
    // Remove Comment HTML
    add_filter( 'pre_comment_content', 'wp_specialchars' );
    
    // Remove HTML shortlink
    remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
    
    // Remove WP 3.0 shortlink
    function empty_shortlink($shortlink, $id, $context, $allow_slugs) {
        return null;
    }
    add_filter( 'get_shortlink', 'empty_shortlink',10,4);
    
    // Disable sitelinks searchbox
    add_filter( 'disable_wpseo_json_ld_search', '__return_true' );
    
    // The editor does not remove span tags without attributes
    function my_adds_alls_elements($init) {
    if(current_user_can('unfiltered_html')) {
    $init['extended_valid_elements'] = 'span[*]';
    }
    return $init;
    }
    add_filter('tiny_mce_before_init', 'my_adds_alls_elements', 20);
    
    // Deregister Contact Form 7 styles
     
    add_action( 'wp_print_styles', 'wps_deregister_styles', 100 );
    function wps_deregister_styles() {
        wp_deregister_style( 'contact-form-7' );
    }
     
    // 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( get_theme_mod( "header_contacts") ) ) {
            wp_deregister_script( 'contact-form-7' );
        }
    }
    #2225

    admin
    Keymaster

    Hi duende!

    Thanks for your contribution but I would like to notice that some parts of your functions.php have specific functionality for your own site so for the rest of the users please copy/paste responsibly 🙂

    #2234

    You’re welcome! I only share some knowledge with the rest, to improve the functioning of the website.
    What I try to copy and paste, I completely agree with you, before copying the code, you have to know well if this serves for each particular website. These modifications can only be done by users with advanced knowledge!

    Casinos Fortune

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.