Insert a button on a page with random number generation

all thing you have to do is use javaScript function JavaScript Example: var random_number = function(){ return Math.floor(Math.random() * 10000) + 1; }; document.getElementById(‘button_text’).onclick = function () { document.getElementById(“input_box”).innerHTML = random_number(); }; jQuery Example: $.randomBetween(0,10000);

WXR slicing script

Googling for “split wxr file” returned several results, including python script for splitting .wxr file GUI for splitting WXR files (OSX and Windows) .Net splitter for WXR files Haven’t tried any of these, but the comments look positive.

Add stylesheets and js to template files when shortcode is used

put wp_enqueue_script() in your shortcode handler. add_shortcode(‘myshortcode’, ‘my_shortcode_handler’); function my_shortcode_handler($atts) { wp_enqueue_script(‘my-script’, plugins_url(‘my-script.js’, __FILE__), array(‘jquery’), ‘1.0’, true); // actual shortcode handling here return “bacon flavored shortcode here”; } this definitely loads the my-script.js file for me. it gets loaded in the footer though. i don’t think there is a way for it to load conditionally … Read more

change $src from wp_register_script in plugins/themes

Well of course you can. All you need to find is what handle they are using for those scripts. let’s say they are uing plugin-script handle. Then you deregister and register script again with your URL. Like this. function wcs_scripts_styles() { wp_deregister_script( ‘plugin-script’ ); wp_register_script( ‘plugin-script’, get_stylesheet_uri(). ‘/js/jquery.script.js’, array( ‘jquery’ ), NULL, true ); } … Read more

Overwrite or Replace code in WP_Footer

Since you ruled out remove_action there is only one way you can do it. And you’ve guessed it: preg_repalce, substr mixture but with a little help and PHP DOM add_action(‘wp_footer’, ‘my_start_footer_ob’, 1); function my_start_footer_ob() { ob_start(“my_end_footer_ob_callback”); } add_action(‘wp_footer’, ‘my_end_footer_ob’, 1000); function my_end_footer_ob() { ob_end_flush(); } function my_end_footer_ob_callback($buffer) { // remove what you need from he … Read more

My scripts-bundle.js file is getting sent to the browser as a stylesheet css file. Help!

Ok, I managed to solve this issue because I was using the wrong WP functions to point my child themes directory and thus my bundled javascript script. I cleared out my functions.php file and added the below and it all works now: function load_js_files() { wp_enqueue_script( ‘script’, get_stylesheet_directory_uri() . ‘/js/scripts-bundled.js’, array ( ‘jquery’ ), 1.1, … Read more

Retrieve URL of Script/Style and Dependencies

wp_enqueue_script() and wp_enqueue_style() both use WP_Dependencies::add() which initializes a new instance of _WP_Dependency (see wp_scripts() and wp_styles()), so all the script’s dependencies are stored in the deps property of the class instance. However, that property only stores the handle names of the script’s dependencies, e.g. jquery-migrate and jquery-core for the default/core jQuery script (handle name: … Read more

wp_add_inline_script not adding when script_loader_tag filtered

The reason this is happening is because the markup that is filtered by script_loader_tag includes the inline scripts. So when you filter it and replace all the HTML tag for a particular script, your filter is removing those inline script tags. If you print out the original value of $tag from within your filter you … Read more

How do I enqueue a JavaScript in my footer via the functions.php file?

First, create a static js file with those inline codes.. !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0]; if(!d.getElementById(id)){js=d.createElement(s);js.id=id; js.src=”https://platform.twitter.com/widgets.js”; fjs.parentNode.insertBefore(js,fjs);} }(document,”script”,”twitter-wjs”); var options = { “url”: “/my-styles.css” }; CustomizeTwitterWidget(options); Then enqueue it at footer as the dependent of twitter-customize script which you already enqueued. function my_footer_enqueue() { wp_register_script( ‘twitter-customize’, get_template_directory_uri() . ‘/js/customize-twitter-1.1.min.js’, array(), ‘1.0’, true ); wp_enqueue_script( ‘twitter-customize’ ); wp_enqueue_script( … Read more