Make jQuery library load before plugin files

If you look at the wp_enqueue_script Codex Documentation, you’ll see one of the options is $deps, this would mean that your script is dependent upon another script, simply add jquery as a dependancy and your scripts will load in the correct place. If you set a handle for the other scripts you can use them … 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

Load js/css files only on specific admin UI pages

The right hooks // Use both for scripts & styles *) wp_enqueue_scripts // (for the frontend) login_enqueue_scripts // (for the login screen) admin_enqueue_scripts // (for the admin dashboard) *) Read this article @wpdevel. Further reading in the Codex about the three hooks admin_menu network_admin_menu user_admin_menu On the admin_enqueue_scripts hook, you have an argument as well: … Read more

tinymce is not defined when not using wp_editor

With help from a colleague, we dug through class-wp-editor.php Here are the necessary scripts to initialise jQuery tinyMCE if wp_editor has not been used beforehand (which calls these scripts). // Get the necessary scripts to launch tinymce $baseurl = includes_url( ‘js/tinymce’ ); $cssurl = includes_url(‘css/’); global $tinymce_version, $concatenate_scripts, $compress_scripts; $version = ‘ver=” . $tinymce_version; $css … 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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)