How to en-queue bootstrap 4 to theme?

You can use action hook and enqueue script and style to the site. function my_scripts() { wp_enqueue_style(‘bootstrap4’, ‘https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css’); wp_enqueue_script( ‘boot1′,’https://code.jquery.com/jquery-3.3.1.slim.min.js’, array( ‘jquery’ ),”,true ); wp_enqueue_script( ‘boot2′,’https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js’, array( ‘jquery’ ),”,true ); wp_enqueue_script( ‘boot3′,’https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js’, array( ‘jquery’ ),”,true ); } add_action( ‘wp_enqueue_scripts’, ‘my_scripts’ ); If you want to add the scripts after jQuery then you can use the … Read more

Enqueue script in specific page

Inside admin-header.php, there’s the following set of hooks: do_action(‘admin_enqueue_scripts’, $hook_suffix); do_action(“admin_print_styles-$hook_suffix”); do_action(‘admin_print_styles’); do_action(“admin_print_scripts-$hook_suffix”); do_action(‘admin_print_scripts’); do_action(“admin_head-$hook_suffix”); do_action(‘admin_head’); The one to always use it admin_enqueue_scripts, both for stylesheet and scripts. More info in this answer. It has one additional argument, the $hook_suffix. This argument is exactly the same as the return value that you get from add_submenu_page() … Read more

Protocol neutral URLS with wp_enqueue_script (SSL issues)?

You can’t — URLs must have a protocol for WordPress to enqueue them. What you can do, though, is detect which protocol to use and then use that. $protocol = is_ssl() ? ‘https’ : ‘http’; $url = “$protocol://example.com/resource”; But for enqueuing scripts from your theme, you should use get_template_directory_uri() or get_stylesheet_directory_uri() which already handle SSL: … Read more

Enqueue custom font file with rel=”preload”

You could try using the style_loader_tag filter. add_action(‘wp_enqueue_scripts’, ‘my_enqueue_scripts’); function my_enqueue_scripts() { wp_enqueue_style(‘my-style-handle’, “https://wordpress.stackexchange.com/fonts/custom-font-folder/CustomFontFile.woff2”, array(), null); } add_filter(‘style_loader_tag’, ‘my_style_loader_tag_filter’, 10, 2); function my_style_loader_tag_filter($html, $handle) { if ($handle === ‘my-style-handle’) { return str_replace(“rel=”stylesheet””, “rel=”preload” as=”font” type=”font/woff2″ crossorigin=’anonymous'”, $html); } return $html; } Here we’re enqueuing the stylesheet using the normal wp_enqueue_style function. We then capture the … Read more