wp_add_inline_script without dependency

wp_add_inline_style() – without dependency The wp_add_inline_style() can be used without a source file dependency. Here’s an example from @Flix: wp_register_style( ‘dummy-handle’, false ); wp_enqueue_style( ‘dummy-handle’ ); wp_add_inline_style( ‘dummy-handle’, ‘* { color: red; }’ ); where we would hook this into the wp_enqueue_scripts action. wp_add_inline_script() – without dependency According to ticket #43565, similar will be supported … Read more

Load a script just to custom post type in admin

Try this code for adding scripts to the edit pages of your portfolio custom post type. add_action( ‘admin_print_scripts-post-new.php’, ‘portfolio_admin_script’, 11 ); add_action( ‘admin_print_scripts-post.php’, ‘portfolio_admin_script’, 11 ); function portfolio_admin_script() { global $post_type; if( ‘portfolio’ == $post_type ) wp_enqueue_script( ‘portfolio-admin-script’, get_stylesheet_directory_uri() . ‘/admin.js’ ); }

How to enqueue scripts on custom post add/edit pages?

You can do it like this (put in your functions.php) : function add_admin_scripts( $hook ) { global $post; if ( $hook == ‘post-new.php’ || $hook == ‘post.php’ ) { if ( ‘recipes’ === $post->post_type ) { wp_enqueue_script( ‘myscript’, get_stylesheet_directory_uri().’/js/myscript.js’ ); } } } add_action( ‘admin_enqueue_scripts’, ‘add_admin_scripts’, 10, 1 );

Adding Additional Attributes in Script Tag for 3rd party JS

you can try to use the script_loader_src filter hook e.g: add_filter(‘script_loader_src’,’add_id_to_script’,10,2); function add_id_to_script($src, $handle){ if ($handle != ‘dropbox.js’) return $src; return $src.”‘ id=’dropboxjs’ data-app-key=’MY_APP_KEY”; } Update i just figured it out myself that the src is escaped by esc_url, so looking a bit more i found the clean_url filter which you can use to return … Read more

How to correctly include jquery-ui effects on wordpress

While WordPress does include the jQuery UI libraries, it does not include the UI/Effects library. That library is separate and standalone. You’ll need to include a copy of the effects.core.js file and enqueue it separately. Note that you should name it jquery-effects-core when en-queuing it, for naming consistency. You can include it like this: wp_enqueue_script(“jquery-effects-core”,’http://example.com/whatever/effects.core.js’, … Read more

Could the WP script/style loader be used to concatenate and gzip scripts and styles in the front-end?

late answer From a brief look: You’d have to use include( admin_url().’load-scripts.php’ ); and include( admin_url().’script-loader.php’ ); Then jump into $GLOBALS[‘wp_scripts’]: Use… $wp_scripts->default_dirs( array_merge( $wp_scripts->default_dirs ,array( ‘/themes/your_theme/js/’ ) ); …to extend it. And then use $wp_scripts->add( $handle, $path_from_content_dir, false/array( $deps ), $ver ) to add a script. Notes: Uncompressed scripts get searched by .dev.js (when … Read more

Is it possible to use wp_localize_script to create global JS variables without a specific script handle?

Instead of using wp_localize_script in that case, you can hook your js variables at wp_head, that way it would be available to all js files like: function my_js_variables(){ ?> <script type=”text/javascript”> var ajaxurl=”<?php echo admin_url( “admin-ajax.php” ); ?>”; var ajaxnonce=”<?php echo wp_create_nonce( “itr_ajax_nonce” ); ?>”; </script><?php } add_action ( ‘wp_head’, ‘my_js_variables’ ) Also as suggested … Read more

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