Import HTML code that loads css and javascript into specific page

Add CSS and JS Particular Page. Put this code in your current active theme function.php file <?php function function_name() { is_page( ‘about-me’ ) //is_page( ‘PAGE_SLUG_NAME’ ) { wp_enqueue_style( ‘stylecss’, get_template_directory_uri() .’/css/style.css’,”, ‘3.3.1’ ); wp_enqueue_script( ‘script’, get_template_directory_uri() . ‘/js/script.js’, array ( ‘jquery’ )); } } add_action( ‘wp_enqueue_scripts’, ‘function_name’ ); ?>

How to call javascript function (jquery) in a shortcode?

Use wp_enqueue_script() with $in_footer parameter set to true, when loading scripts with your shortcode. To pass data from the PHP part of your code to the JS part use wp_localize_script(). wp_enqueue_script( ‘script_name’, ‘/script-location/script.js’, array(), ‘1.0.0’, true ); $data_array = array( ‘key_1’ => ‘val_1’, ‘key_2’ => ‘val_2’ ); wp_localize_script( ‘script_name’, ‘data_object_name’, $data_array ); You now can … Read more

Unserialize WP_Options options programatically?

The get_option and update_option functions in PHP automatically handle serialization/unserialization for you: https://codex.wordpress.org/Function_Reference/get_option If you need to interface with these functions using JavaScript (assuming JavaScript and not Java, as others have pointed out) you could register an AJAX endpoint that calls these functions for you that you can interface with via JavaScript on the front-end: … Read more

How to get this jQuary script working?

Oh okay.. I think I solved it. I put the script in the header.php (I think “into the loop” as they say?) just behind the opening <header>-tag: <body> <header> <script type=”text/javascript”> (function($) { $(document).ready(function(){ $(window).scroll(function(){ if ($(this).scrollTop() > 200) { $(‘#menu’).fadeIn(500); } else { $(‘#menu’).fadeOut(500); } }); }); })(jQuery); </script>

Custom Javascript not working? [closed]

There are a few problems but the main one is when sidebarEffects.js is loaded the HTML it’s looking for doesn’t exist yet. So… var container = document.getElementById( ‘st-container’ ) // and buttons = Array.prototype.slice.call( document.querySelectorAll( ‘#st-trigger-effects > button’ ) ) are both empty when the script is run. Easiest way to fix it is to … Read more