Tag Info

Hot answers tagged

14

Wordpress as a nice function is_active_widget that you can use in your __construct and test if the widget is present in the current page and add your scripts/styles based on that ex: function __construct() { parent::__construct(__CLASS__, 'BasicWidget', array( 'classname' => __CLASS__, 'description' => "This is a basic widget ...


12

the $wp_scripts global holds all the script data: function wpa54064_inspect_scripts() { global $wp_scripts; foreach( $wp_scripts->queue as $handle ) : echo $handle; endforeach; } add_action( 'wp_print_scripts', 'wpa54064_inspect_scripts' );


10

I for myself use a combination of: one file dedicated to the one-time script using a transient to stop the script from accidentally running more than once using capability-management or user-control to ensure the script is just run by me. Structure I use a file (onetime.php) in my include-folder inc, which is included in the functions.php, and deleted ...


10

Are you using a Theme that you control? If not, then every time the Theme updates, you'll lose your modifications to the header. Or else, you'll have to fork the Theme, or maintain/backport your changes every time the Theme updates. Do you only use Plugins under your control? If not, then you'll have to check for script conflicts every time you activate ...


9

You can also do this: run onetime.php and rename it after execution. if ( current_user_can( 'manage_options' ) ) { if( ! file_exists( '/path/to/onetime.php' ) ) return; add_action( 'wp_footer', 'ravs_my_onetime_function' ); // execute my function on the desired hook. } function ravs_my_onetime_function() { // all my glorious ...


8

For the record this entirely the wrong thing to do. Themes should avoid (read never!) de-register the WordPress registered jQuery scripts (plug-ins should absolutely never do this). If a theme is to de-register the jquery script (to replace it) then it should re-register it properly: wp_register_script( 'jquery', ...


8

You don't want to edit core WordPress code. You don't need to edit core WordPress code to do what you need to implement. First, you need to study the WordPress templating (i.e. Theme) functionality. Then, you need to study Plugins and the WordPress Hooks API, including its Action Hooks and its Filter Hooks. To do what you're describing, you definitely ...


7

Modify a registered style's path I wanted to tweak the path to one of the WordPress admin stylesheets so i could keep requests down, and because it makes little sense to include two stylesheets, when the one i'm calling redefines all the styling in the stylesheet enqueued by WordPress. The idea is basically to re-point the existing style at a different ...


7

I am not sure about the extra quotes. The best way to include a java script file is with wp_enqueue_script() as indicated here in the codex. The safe and recommended method of adding JavaScript to a WordPress generated page and WordPress Theme or Plugin is by using wp_enqueue_script(). This function includes the script if it hasn't already been ...


6

I created a command line Phing script for this, it's nothing special other than loading an external script to run, the reason I used it via the CLI is because: I don't want it to load by mistake (need to type a command) It's secure since it can be run outside the web root, in other words it can effect WP but WP cannot reach the script in any way. It does ...


6

Digging through https://github.com/WordPress/WordPress/blob/3.5.1/wp-includes/class.wp-dependencies.php all registered scripts are stored in the global $wp_scripts. You can access them directly through that, but I prefer to use the API when it exists. In this case, $wp_scripts->query() returns a particular registered script (a _WP_Dependency object - ...


6

**YES** 1. It only loads scripts when needed Important for load speed. 2. It safely handles dependencies. Reduces errors, duplicate loading and js clashing. 3. It handles load order and placement Tell it where to load and when. 4. Its handles $src properly Moving the site around, perfect. 5. It has ...


5

However, I am unsure how to get full access to the Source Code of the site. You will need FTP/SFTP access to for decent development experience. I have privileged access to the backend of the site but in wordpress when you go to edit it only shows some of the basic html tags while hiding the and tags and code. Is there any way edit the page in its ...


5

Another pretty simple way of running a one-time script is to do this by means of an MU plugin. Put the code in some PHP file (e.g., one-time.php) that you upload to your MU plugins' folder (by default /wp-content/mu-plugins), adjust the file permissions, run the plugin (i.e., according to your chosen hook, you basically just have to visit the ...


5

There's a global variable called $wp_scripts which is an instance of the WP_Scripts class. It doesn't have a public API for looking at registered or enqueued scripts, but you can look inside the object and see what's going on. You can see all the registered scripts with: global $wp_scripts; var_dump( $wp_scripts->registered ); To see the enqueued ...


4

If you refer to this script, this is not included in wordpress. See the codex for list of scripts included in wp you will not find it. If you don't trust codex, you can look into the folder wp-includes/js and search for easing script... it's not there. Edit (additional info) Answer above just 'strictly' respond to the OP question, because the plugin he ...


4

Sometimes I used a function hooked on plugin deactivation. See here Update Old Links To Pretty Permalinks Custom Post Type Once only admins can activate plugins, there a capability check as a side effect. There is no need to delete file once deactivated it will not included by wordress. In addiction if you want to run again it you can. Activating and ...


4

add_action('wp_enqueue_scripts', 'no_more_jquery'); function no_more_jquery(){ wp_deregister_script('jquery'); } That will deregister jquery. But why wouldn't you want jQuery at all? If you mean to simply use your own, you should do it in that function, like this: add_action('wp_enqueue_scripts', 'no_more_jquery'); function no_more_jquery(){ ...


4

I think that none the options you has posted actually works. You are only registering the script, you need to enqeue them. Also, you should use wp_enqueue_scripts() action hook instead of init(). function register_scripts() { wp_register_script( 'newsletter', get_stylesheet_directory_uri() . '/scripts/scripts.js', array( 'jquery-migrate' ), null ...


4

To always get latest plugin take for example my plugin: http://wordpress.org/extend/plugins/wordpress-file-monitor-plus/ the download link for the latest is: http://downloads.wordpress.org/plugin/wordpress-file-monitor-plus.1.1.zip but if you remove the version from the download link you always get the latest version: ...


4

There is no designated way to change details of registered script/style dependency after the registration. Your options are: deregister it and register again with desired data modify data in corresponding global variable handle timing in other ways, such as manual output and hook priorities


4

This is not possible the way you think. It would maybe be possible if you use Reflections or debug_backtrace(), but there's no reliable way to do this. WordPress does not keep a stack or queue where it tracks file names. The only thing I could imagine is just hooking into the action and inside wp_enqueue_scripts(): wp_enqueue_scripts and attach a ...


3

Your question is a bit broad. We actually have a one question per post policy. I'm going to try to answer though My first question is, shouldn't most themes that you download out there automatically include jQuery in your header anyway? Well, basically correct. So many features today in a theme needs jquery to run properly. I haven't came across a ...


3

I don't see how the first block of code works and not the second since in both cases all you are doing is registering the script, not enqueueing it. If you don't enqueue nothing will show up on the front end at all. function register_scripts() { wp_register_script( 'newsletter', get_stylesheet_directory_uri() . '/scripts/scripts.js', array( ...


3

You can change the order of the scripts but can't have one script load before anything else. The HTML 5 enabling script is IE conditional so you probably don't want to use wp_enqueue_script as it would load for all browser users which isn't necessary. It's ok to hard code it in your themes header. Even Twentyeleven does it this way. Also there is nothing ...


3

There's an in_footer parameter that you can pass to wp_enqueue_scripts - does that work? I would hook to admin_enqueue_scripts, check the $page for location, and enqueue your script there, with 'in_footer' as true. Example: add_action( 'admin_enqueue_scripts', 'enqueue_my_script' ); function enqueue_my_script( $page ) { if ($page !== 'edit.php') ...


3

This widget enqueues all possible required scripts for the footer, but it also sets a hook on wp_print_footer_scripts that will deregister the scripts before they are printed, unless you change the array when printing the widget. class WPSE16208_Widget extends WP_Widget { // Key is script handle, value is boolean: // true if it should be printed, ...


3

It is added by the Domain Mapping Plugin and i believe (i might be wrong) it is used to log users into all MU sites with a single login. to remove it: add_action('wp_loaded', 'remove_unwanted_js'); function remove_unwanted_js(){ remove_action( 'wp_head', 'remote_login_js_loader' ); }


3

This isn't really a WordPress question - more a generic web development issue. These are some open source tools that can be used for scripting and testing a web browser session. Selenium Cucumber Watir


3

When you register a plugin option page you get a hook from the registration function: $hook = add_menu_page( 'T5 Demo', // page title 'T5 Demo', // menu title 'manage_options', // capability 't5-demo', // menu slug 'my_render_page' // callback function ); Use this hook to enqueue the scripts and styles: ...



Only top voted, non community-wiki answers of a minimum length are eligible