When does WordPress wrap inline scripts in CDATA?

Actually, it is not WordPress that is inserting the CDATA tags, but the visual editor, TinyMCE. Details of TinyMCE are offtopic here, but you can read a solution to this on Stackoverflow. That said, stopping TinyMCE may not be the full solution you want. WordPress itself also has a function for adding CDATA tags, wxr_cdata, … Read more

How to create filterable portfolio in WordPress?

You’re setting $terms_portfolio too early. You’re using get_the_terms( get_the_ID(), ‘portfolio_categories’), but get_the_ID() won’t be the current portfolio in the loop because $portfolio_query->the_post() hasn’t run yet. Change this bit: <?php $portfolio_query = new WP_Query(array( ‘post_type’ => ‘portfolios’, ‘order’ => ‘DESC’, )); $terms_portfolio = get_the_terms( get_the_ID(), ‘portfolio_categories’); ?> <?php if($portfolio_query->have_posts()) : while($portfolio_query->have_posts()) : $portfolio_query->the_post(); ?> <div class=”col-md-4″ … Read more

Using JavaScript and JQuery in Page

jQuery is default active in WP, no need to enable it. There are 2 ways of including your own jQuery in WP: Enqueue your own file containing the jQuery (preferred method) Use the wp_head or wp_footer action hook to include a script with jQuery. I’m only going to explain how to enqueue scripts in WP. … Read more

Understanding WordPress child theme custom JS loading

This is the proper way to load a custom javascript in your child theme, wp_localize_script is only necessary if you need to exchange data between JS and PHP (Client and server). function assets() { wp_register_script(‘ajax_filter’, get_stylesheet_directory_uri() . ‘/js/ajax-filter-posts.js’, [‘jquery’], ‘1.0’, false); wp_enqueue_script(‘ajax_filter’); wp_localize_script( ‘ajax_filter’, ‘mdu’, array( ‘nonce’ => wp_create_nonce( ‘mdu’ ), ‘ajax_url’ => admin_url( ‘admin-ajax.php’ … Read more

How to use wp-ajax in wp-cron

First of all, think about using the new REST API instead of Admin-AJAX in your environment where JavaScript is available. Now to answer your question: JavaScript isn’t available for wp-cron, as these requested solely run on the server and not on some interpreted HTML/JavaScript. So what can you do? Well, just schedule another event if … Read more

jQuery Hoverintent plugin in TwentyEleven Menu [closed]

Here is the code I have in my functions.php file: /** * Hoverintent Plugin for the menu * @since Theme 1.0 */ function theme_hover_menu() { wp_register_script(‘hoverintent_script’, get_template_directory_uri() . ‘/js/hoverintent.js’, array(‘jquery’), ‘r6’ ); wp_enqueue_script(‘hoverintent_script’); } add_action(‘wp_enqueue_scripts’, ‘theme_hover_menu’); This is step 1… Next? Comments? Solutions? I will edit this post once I will have found the answer. … Read more

Why does this Quick Edit checkbox save the value only when unchecked?

Why the headline_news meta data is deleted on the Edit Post screen, with a fix The qedit_save_post() function stomps on headline_news because $_POST[‘headline_news’] is not set when using the post edit screen. Since the custom fields editor is being used for headline_news and there is no custom meta box involved, we’ll let the built-in custom … Read more