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 ...


9

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' );


9

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 ...


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

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 ...


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

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 ...


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 ...


5

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 ...


5

**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 ...


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

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 - ...


4

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 ...


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

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 ...


3

You can look into this post: http://ken.ph/first-image-of-wordpress-post-as-thumbnail/ Or if you're comfortable with MySql try using this (obviously check it on local database first): INSERT into wp_postmeta (meta_value, meta_key, post_id) SELECT DISTINCT(ID), post_type , post_parent FROM wp_posts WHERE post_type= 'attachment' AND post_parent !=0 AND ...


3

Use wp_enqueue_script in your shortcode handler, in WordPress >= 3.3 it will be added to the page in the wp_footer action. Pass any data you need from PHP to JavaScript via wp_localize_script.


3

General answer: you can call wp_enqueue_script() directly inline in the template, as of WordPress 3.4 (IIRC). So, if you have: <script src="myscriptforthispageonly.js"></script> You could replace it with: <?php wp_enqueue_script( 'this-page-script', get_template_directory_uri() . '/myscriptforthispageonly.js', array( 'jquery' ), null, ...


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

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(){ ...


3

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 ...


3

If done right there should be a callback hooked to wp_enqueue_scripts which has either wp_enqueue_script or both wp_register_script and wp_enqueue_script in it. Something like the following from the Codex: function themeslug_enqueue_script() { wp_enqueue_script( 'my-js', 'filename.js', false ); } add_action( 'wp_enqueue_scripts', ...


3

Hi @mrclay: Good questions. WordPress Multisite is Many Independant Sites, not Many Dependant Sites To answer your aside, WordPress multisite was designed to be a collections of independent WordPress installs collected into one where each site is likely to be very different, unlike your use-case. So each site has it's own theme and WordPress wants those ...


3

I haven't tried it, but this might do it: global $wp_scripts; if (is_a($wp_scripts, 'WP_Scripts')) { $wp_scripts->queue = array(); } Basically just resetting the scripts queue to blank. Should work, I think. You'd want this right at the top of your attachment template, probably. From an optimization perspective, it would be faster to use the ...


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

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 ...



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