How to add php within jquery

I see no reason for you to use PHP in your JavaScript file. Enqueue your script properly using the wp_enqueue_scripts hook and then use the wp_localize_script()function to pass your data to your JavaScript code. <?php function wpa67325_enqueue_scripts() { wp_enqueue_script( ‘some_handle’, ‘filename.js’, false ); $translation_array = array( ‘some_string’ => __( ‘Some string to translate’ ), ‘a_value’ … Read more

Custom attributes to javascript tags

I am afraid this is impossible. The markup is hard coded in /wp-includes/class.wp-scripts.php: if ( $this->do_concat ) $this->print_html .= “<script type=”text/javascript” src=”https://wordpress.stackexchange.com/questions/70184/$src”></script>\n”; else echo “<script type=”text/javascript” src=”https://wordpress.stackexchange.com/questions/70184/$src”></script>\n”;

Migrating site, only header shows

The PHP Fatal Error will halt any further output, so yes this is the reason that only the header is displayed. Did you install the theme via FTP or did you install using the zip upload? I’d guess that you missed some files when uploading.

Change Default Content when Creating a Post based on Previous Category Choice

You should have linked to the original Q&A since the beginning… Another great code from @JanFabry, btw 🙂 Force category choice before creating new post? Using exactly the code provided in his answer, this is how to make the filter default_content work: add_filter( ‘default_content’, ‘wpse_71772_default_content’, 10, 2 ); function wpse_71772_default_content( $content, $post ) { if( … Read more

Sorting custom post types in edit.php : Post disappear

The problem is ‘meta_key’ => ‘large_feature’, in your last function, here the “large_feature” is a taxonomy, not a “meta_key”. Infact there is no post in wordpress which has “large_feature” as a “meta_key”. That’s the reason wordpress didn’t display any posts. About ordering by taxonomy terms, wordpress doesn’t allow that like this. You can however customize … Read more

Call javascript functions from each page

I would create a custom field containing the function to be called, for example called ‘function_to_call’. In the templatefile add the code $function_to_call = get_post_meta( get_the_ID(), ‘function_to_call’, true ); if ( $function_to_call != “” ) { echo ‘ jQuery(document).ready(function($){ ‘ . $function_to_call . ‘() }); ‘; } Doing this only outputs the function if you … Read more

AJAX function not working [closed]

You have an error on this line: var appendHTML = ‘<div class=”ajax-loading-screen appended”> Be careful with multi-line string in Javascript. It doesn’t work the way it does in PHP. https://stackoverflow.com/questions/805107/how-to-create-multiline-strings

Fatal error: allowed memory size when after using enqueue_script

The problem is the de-registering the core-bundled version of jQuery, and re-registering using your own, arbitrary version. Do not de-register core-bundled versions of scripts (especially jQuery) in order to register arbitrary/custom versions of those scripts. Doing so can and will cause breakage and unintended consequences. If you’re doing so in order to cause your custom … Read more