Automatically decrease font size for long words

I’ve done something similar taking the simple approach of adding a CSS class to titles based on their character count. That CSS class then decreases letter-spacing and/or font-size. // Count the characters, taking Unicode into account $chars = mb_strlen($post->post_title); // For every 10 characters after the first 20, add a size $size = max(0, ceil(($chars … Read more

Adding Colorpicker Field To Category

This has been updated for WordPress 4+ with the introduction of Term Meta. The code is heavily commented. :: My Functions – functions.php :: The below function is to display the colorpicker on the “Add New Category” screen: /** * Add new colorpicker field to “Add new Category” screen * – https://developer.wordpress.org/reference/hooks/taxonomy_add_form_fields/ * * @param … Read more

How do I use WP’s jQuery

WP’s jQuery is not mapped to $ like you may expect, it is loaded in noConflict mode so you’ll need to use jQuery() instead of $(), unless you map it yourself. When you include your js file you’ll want to make sure to set jQuery as a dependency as well: wp_enqueue_script( ‘your-script-handle’, get_stylesheet_directory_uri() . ‘/js/your-script.js’, … Read more

How do I rebind event after widget save

WordPress provides callbacks for widgets interactions. You’re seems interested in two of them: widget-added, widget-updated Usage example: jQuery(document).on(‘widget-updated’, function(e, widget){ // do your awesome stuff here // “widget” represents jQuery object of the affected widget’s DOM element });

AJAX call returns 0

Note that the action should be inside the data key. In your post request there is no key named as action therefore, the callback function is never being called. Consider this example:- jQuery.ajax({ type:”POST”, url: “/wp-admin/admin-ajax.php”, data: { action: “my_test_action”, form_data : newFormChange }, success: function (data) { console.log(data); } }); Also Note: Never use … Read more

WooCommerce single product edit flexslider settings

After a little digging through the source I found there is a filter called woocommerce_single_product_carousel_options that can be used to modify the flex slider options for example: function my_product_carousel_options($options) { $options[‘animation’] = ‘fade’; return $options; } add_filter(“woocommerce_single_product_carousel_options”, “my_product_carousel_options”, 10);

Hook the Keydown Event in the TinyMCE Post Editor

the TinyMCE Editor has its own keydown event handler and its hooked to a function on initiation so to do that you can create a tinymce plugin or use the wordpress initiation of it with tiny_mce_before_init hook like this: add_filter( ‘tiny_mce_before_init’, ‘wpse24113_tiny_mce_before_init’ ); function wpse24113_tiny_mce_before_init( $initArray ) { $initArray[‘setup’] = <<<JS [function(ed) { ed.onKeyDown.add(function(ed, e) … Read more

Set Featured Image programmatically (in admin) with JavaScript?

You need to do an ajax call with action: ‘set-post-thumbnail’ Check in admin-ajax.php (line 1477 in 3.3.2) for the expected values and nonce, but in general you need to send post_id, attachment_id and nonce. The nonce should come from: wp_create_nonce( “set_post_thumbnail-$post_id” ); The admin does something like: uploader.bind(‘FileUploaded’, function(up, file, response) { jQuery.post(ajaxurl, { action:”set-post-thumbnail”, … Read more