How can we help?
If you are looking for support for our PokaTheme, this is the place!
Home › Forums › PokaTheme support › Move script from header to footer and increase loading speed
Tagged: functions.php
- This topic has 2 replies, 2 voices, and was last updated 6 years, 1 month ago by duendecasino@gmail.com.
-
AuthorPosts
-
July 25, 2018 at 3:30 pm #2216duendecasino@gmail.comParticipant
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.`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’ );
}
}`July 26, 2018 at 12:31 pm #2225adminKeymasterHi 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 🙂
July 26, 2018 at 3:18 pm #2234duendecasino@gmail.comParticipantYou’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!- This reply was modified 6 years, 1 month ago by duendecasino@gmail.com.
-
AuthorPosts
- You must be logged in to reply to this topic.