从我的Wordpress网站

时间:2017-10-19 22:10:39

标签: php ajax wordpress google-api

任何对googleapis的引用都将阻止我在中国的网站。如何删除这些引用?

以下是我的grep搜索google api参考的结果:

./codesearch.php:$command = "grep -ri 'ajax.googleapis.com' ./*"; ./wp-content/cache/all/privacy-policy/index.html: ./wp-content/cache/all/privacy-policy/index.html: ./wp-content/cache/all/contact/index.html: ./wp-content/cache/all/contact/index.html: ./wp-content/cache/all/index.html: ./wp-content/cache/all/index.html: ./wp-content/cache/all/author/boomerlanglearning/index.html: ./wp-content/cache/all/author/boomerlanglearning/index.html: ./wp-content/cache/all/my-account/index.html: ./wp-content/cache/all/my-account/index.html: ./wp-content/cache/all/my-account/lost-password/index.html: ./wp-content/cache/all/my-account/lost-password/index.html: ./wp-content/cache/all/terms-and-conditions/index.html: ./wp-content/cache/all/terms-and-conditions/index.html: ./wp-content/plugins/woocommerce-checkout-manager/woocommerce-checkout-manager.php: // wp_enqueue_script( 'jquery-lib', '//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js' ); ./wp-content/plugins/booster-plus-for-woocommerce/includes/settings/wcj-settings-general.php:   'default' => '//ajax.googleapis.com/ajax/libs/jqueryui/1.9.0/themes/base/jquery-ui.css', ./wp-content/plugins/booster-plus-for-woocommerce/includes/classes/class-wcj-scripts.php:  $datepicker_css_path = '//ajax.googleapis.com/ajax/libs/jqueryui/1.9.0/themes/base/jquery-ui.css'; ./wp-content/plugins/woocommerce-bookings/woocommerce-bookings.php:  wp_enqueue_style( 'jquery-ui-style', '//ajax.googleapis.com/ajax/libs/jqueryui/' . $jquery_version . '/themes/smoothness/jquery-ui.min.css' ); ./wp-includes/script-loader.php: $scripts->add( 'prototype', 'https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js', array(), '1.7.1'); ./wp-includes/script-loader.php: $scripts->add( 'scriptaculous-root', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/scriptaculous.js', array('prototype'), '1.9.0'); ./wp-includes/script-loader.php:   $scripts->add( 'scriptaculous-builder', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/builder.js', array('scriptaculous-root'), '1.9.0'); ./wp-includes/script-loader.php: $scripts->add( 'scriptaculous-dragdrop', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/dragdrop.js', array('scriptaculous-builder', 'scriptaculous-effects'), '1.9.0'); ./wp-includes/script-loader.php:   $scripts->add( 'scriptaculous-effects', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/effects.js', array('scriptaculous-root'), '1.9.0'); ./wp-includes/script-loader.php: $scripts->add( 'scriptaculous-slider', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/slider.js', array('scriptaculous-effects'), '1.9.0'); ./wp-includes/script-loader.php:    $scripts->add( 'scriptaculous-sound', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/sound.js', array( 'scriptaculous-root' ), '1.9.0' ); ./wp-includes/script-loader.php:  $scripts->add( 'scriptaculous-controls', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/controls.js', array('scriptaculous-root'), '1.9.0'); Grep job over.

以下是我添加到子主题的functions.php文件中的代码:

function modify_jquery() {
if (!is_admin()) {

    wp_deregister_script('jquery');
    wp_register_script('jquery', 'https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js', false, '1.9.0');
    wp_enqueue_script('jquery');
    }
}
   add_action('init', 'modify_jquery');

1 个答案:

答案 0 :(得分:1)

add_action('wp_enqueue_scripts', 'modify_jquery', 99); function modify_jquery(){ wp_dequeue_script( 'jquery'); wp_deregister_script( 'jquery'); wp_register_script('jquery', 'https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js', false, '1.9.0'); wp_enqueue_script('jquery'); // repeat for your other googleapi scripts } 应该根据需要为非管理员前端完成工作。

function dequeue_unnecessary_fonts() {
  wp_dequeue_style( 'hemingway_googleFonts-css' );
  wp_deregister_style( 'hemingway_googleFonts-css' );
  wp_dequeue_style( 'hemingway_googleFonts' );
  wp_deregister_style( 'hemingway_googleFonts' );
}
// add_action( 'wp_print_styles', 'dequeue_unnecessary_fonts',20 );
add_action( 'wp_enqueue_scripts', 'dequeue_unnecessary_fonts',20 );
// wp_print_styles (still) works for me (it can affect admin styles)
// but post WP3.3 the Codex recommends using  above style functions with wp_enqueue_scripts instead


function hem_script_fix() {
  wp_dequeue_script( 'hemingway_global' );
  wp_enqueue_script( 'hemingway_global', get_stylesheet_directory_uri() . '/global.js', array( 'jquery' ) ); 
  // identifies script is dependent on jquery which must be "loaded" earlier
}
add_action( 'wp_enqueue_scripts', 'hem_script_fix' );

上面是从您的代码修改的 - 但在我的情况下脚本dereg / reg和“延迟”优先级99是不必要的(见下文)。

您的grep输出包含可能具有依赖关系的脚本,例如'jquery'和样式表。我没有趟过你的grep;但下面是一个剪切和粘贴工作示例,用于解析样式表并处理子函数.php中的脚本依赖关系,用于海明威主题。

{{1}}