php 排队WordPress的脚本和样式

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 排队WordPress的脚本和样式相关的知识,希望对你有一定的参考价值。

class MyClass {

  function __construct() {
    add_action('admin_enqueue_scripts', 'plugin_scripts');
  }
  
  function plugin_scripts()
  {
      wp_enqueue_style('bootstrap', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css', false, '1.0.0');
      wp_enqueue_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array(), '1.0.0', true);
      wp_enqueue_script('bootstrap-js', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', array(), '1.0.0', true);
  }
}

new myClass();


// Refer to the class elsewhere in the plugin
global $my_class;
$my_class = new MyClass()
// display value of the variable

die($hook)

// echo variable 

printf('<pre>');
echo var_dump($arguments);
printf('</pre>');
/**
 * PLUGIN
 * Enqueue scripts and styles - for all admin pages.
 */

function plugin_scripts()
{
    wp_enqueue_style('bootstrap', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css', false, '1.0.0');
    wp_enqueue_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array(), '1.0.0', true);
    wp_enqueue_script('bootstrap-js', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', array(), '1.0.0', true);
}
add_action('admin_enqueue_scripts', 'plugin_scripts');


/**
 * PLUGIN
 * Enqueue scripts and styles - for a particular admin page.
 */
function plugin_name_scripts($hook)
{
    if ('toplevel_page_XXXXX' != $hook) {
        return;
    }
    wp_enqueue_style('bootstrap', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css', false, '1.0.0');
    wp_enqueue_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array(), '1.0.0', true);
    wp_enqueue_script('bootstrap-js', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', array(), '1.0.0', true);
}
add_action('admin_enqueue_scripts', 'plugin_name_scripts');



/**
 * THEME
 * Enqueue scripts and styles
 */
 
 
function theme_scripts()
{
    wp_enqueue_style('style-name', get_stylesheet_uri() );
    wp_enqueue_script('script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true);
    wp_enqueue_style('bootstrap', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css', false, '1.0.0');
    wp_enqueue_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array(), '1.0.0', true);
    wp_enqueue_script('bootstrap-js', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', array(), '1.0.0', true);
}
add_action('wp_enqueue_scripts', 'plugin_scripts');
function debug_console($data) {
      $mode = 'dev';
      $output = $data;
      if (is_array($output)) {
          $output = implode(',', $output);
      }
      if ($mode === 'dev') {
          echo "<script>console.log( 'DEBUG: " . $output . "' );</script>";
      }
  }

// usage with some variable
debug_console($hook);

以上是关于php 排队WordPress的脚本和样式的主要内容,如果未能解决你的问题,请参考以下文章

php WordPress:注册Gravity Forms样式表,只在联系页面#snippet #WordPress上排队

php 排队样式和脚本父母子主题

php 基本WP排队脚本和样式

wordpress主题制作:引入外部CSS样式文件和JS脚本文件-要不要注册样式表(未完待续)

php 当您尝试使用相同的句柄或文件名和位置在WordPress中排队脚本时会发生什么?

WordPress排队脚本-jQuery