Resolving Javascript errors likely related to Gantry framework

Fixed. Thanks to some feedback on reddit (see this thread and this one), I learned that the issue was that the mootools.js script was being loaded far too late. I solved it (rather inelegantly, I’m sure) by adding this line to themes/rt_gantry_wp/index.php, around line 30 or so (before the if blocks): $gantry->addScript(‘/wp-content/plugins/gantry/js/mootools.js’); It’s no longer … Read more

Remove CSS & JS files from WordPress Main Page For Increase Pagespeed?

Does it work any better added to a hook with the conditionals inside? function my_deregisters() { if ( !is_single() ) { remove_action(‘wp_head’, ‘wp_page_numbers_stylesheet’); //wp_deregister_style( ‘fancybox’ ); // i think this can be removed //wp_deregister_script( ‘fancybox’ ); // i think this can be removed wp_dequeue_script(‘fancybox’); wp_dequeue_style(‘fancybox’); remove_action(‘wp_print_scripts’, ‘mfbfw_load’); remove_action(‘wp_print_styles’, ‘mfbfw_css’); remove_action(‘wp_head’, ‘mfbfw_init’); remove_action(‘wp_head’, ‘cforms_style’); } } … Read more

How to add custom javascript into from custom plugin

You must use the hook to enqueue the scripts in WordPress. Use the hook wp_enqueue_scriptsfor the front end and admin_enqueue_scripts for the back end side. If you are enqueueing scripts and styles, you will want to use one of these three hooks: wp_enqueue_scripts (for the frontend) login_enqueue_scripts (for the login screen) admin_enqueue_scripts (for the admin … Read more

How do I insert JS tracking code to a page with the WP editor?

Use conditional tags. Change the 5th parameter to load in the footer. Change get_stylesheet_directory_uri() to get_template_directory_uri() for use in parent themes. add_action( ‘wp_enqueue_scripts’, ‘add_tracking_scripts’ ); function add_tracking_scripts() { if ( is_page(‘slug’) ) { wp_register_script( ‘tracking-script’, get_stylesheet_directory_uri() . ‘/tracking-script.js’, false, ‘1.0’, true ); wp_enqueue_script( ‘tracking-script’ ); } } Source http://codex.wordpress.org/Function_Reference/wp_enqueue_script

Ajax – Call to undefined function get_option()

You’re firing a request to a PHP file that won’t have the WordPress library loaded – hence the undefined function error. You could manually load in WordPress with something like require ‘../../../wp-load.php’. Or, better yet, use the awesome AJAX API. Just fire your request to wp-admin/admin-ajax.php and then register a callback in your plugin or … Read more

Show Post Content with AJAX

Create the JSON endpoint that accepts a WP_Post ID. add_action( ‘rest_api_init’, function() { register_rest_route( ‘api/v2’, ‘/post/(?<id>\d+)’, array ( ‘methods’ => ‘GET’, ‘callback’ => ‘get_post_content’, ) ); } ); Handle the endpoint to return a post’s content based on the ID passed. function get_post_content( WP_REST_Request $request ) { $post = get_post( absint( $request->get_param( ‘id’ ) ) … Read more

Any required callbacks to WP.com or WP.org?

It is a little hard to quickly audit WP code base for wordpress.org links, because they are extensively used in inline documentation. On top of my head the main (if not only) requests are probably to api.wordpress.org for updates. For resources WP generally only uses bundled assets. The two notable exceptions are: Deprecated libraries (such … Read more