New answers tagged

1

Page load is a request, the software run, gives a response and close execution. Later Ajax is another request, totally separated. I you want objects to be persistently avaible between requests, you only have two options: use transients API or use object cache API combined with a cache plugin (object cache api is not persistent by default). A very basic ...


1

Ah, I get it. When you enqueue your admin script, add 'wp-util' as a dependancy. wp_enqueue_script( 'script_handle', plugin_dir_url( __FILE__ ) . 'script.js', array( 'jquery', 'wp-util' ), '1.0', true );


0

You have to load your javascript Snippet inside your header. You'll have to options: Edit your themes header.php and put the code before the closing tag Insert your code into the header with a custom function inside your functions.php function my_custom_js() { echo '<script type="text/javascript"> jQuery(document).ready(function($){ ...


0

You need to change the enqueueing part to this: function skinsave_2016_slider() { wp_enqueue_script( 'skinsave_2016-slider-js', get_bloginfo( 'template_url' ) . '/js/slider-js.js', array(), null, true); } add_action('wp_enqueue_scripts', 'skinsave_2016_slider'); The problem was your function content_url() returns http://yourdomain.com/wp-content, and ...


0

The best practice is the following: Put your Javascript code in a file, yourcustomjs.js, and store it in your theme folder. I would recommend yourtheme/js/yourcustomjs.js. Be sure that you wrap your script, where needed, in a Document.ready function like the following: jQuery(document).ready(function($) { // your code }); This enables you to ensure ...


1

Firstly, you don't need to add scripts in footer.php manually. Secondly, if there are no script dependencies, you have to declare empty array: array(), rather than array(''). Due this mistake scripts are not loading except Bootstrap. The correct code is: function imk_scripts() { wp_enqueue_script( 'bootstrap_js', ...


-3

Write this in your theme's functions.php file function category_enqueue_script() { $cat_education_id = 'xx'; // category id for "education" $cat_dog_id = 'yy'; // category id for "dog" if ( is_category() && ( is_category( $cat_education_id ) || is_category( $cat_dog_id ) ) ) { wp_enqueue_script( 'my-js', 'filename.js', false ); ...


0

If you're trying to make the wordpress_logged_in_HASH cookie info available to javascript to set on the client side using javascript (and thus avoiding re-rendering the page) then I think you'll have more success re-architecting to come up with another solution. The wordpress_logged_in cookie is a httponly cookie which means you don't have access to it on ...


0

I didn't get main part of your question. Still let me try: document.getElementById('InOrCm').value = "in"; That mean you are adding value to the input with id "InOrCm". If I am getting you then your syntax is right. Double check your 'id' name. check with console output. document.getElementById('InOrCm').value = "in"; ...


1

wp_logout is being triggered server side when the user is logging out, but the fact that it is being triggered do not indicate that there is a browser on the other side that actually triggered it. For example a user might log out via Ajax and then the JS code will not be evaluated. In any case, it is much better to define a logged out user as one that do ...


0

Okay. Got it working.... I used the simple version: add_filter( 'admin_post_thumbnail_html', 'basic_add_opacity_to_feature_thumb_box'); //same as before function basic_add_opacity_to_feature_thumb_box( $myhtml ) { $selected_option = get_post_meta( get_the_ID(), 'basic_opacity', true ); // get the current value for ( $i = 0; $i <= 1; $i = $i + 0.1 ) { ...


0

Ok after trying a bunch of different plugins, scripts, and custom coding, I've come across one that seems to be perfect! Only thing now is to figure out how to implement it in my site. My Solution


0

I actually just wanted to make a comment but..(reputation is too low) so doing it this way. If for some reason two versions of jQuery are loaded (which is not recommended), calling $.noConflict( true ) from the second version will return the globally scoped jQuery variables to those of the first version. So to solve your 'issue' (if I am correct) the ...


0

As already mentioned in my comment above, there was not much information to work with. Assuming that a quick workaround using CSS code to overrule settings is enough, here a snippet which will hide the output as asked. Be aware that this will hide those CSS classes for the whole site. Add the snippet below at the end of your style.css in the folder ...


0

Not sure why @RockerMaruf answer got downvoted. That is the best way to do this. The example you have in your question can be used like this below (as seen in roots/soil plugin), but as @Rarst suggested it will break some things (like html5shiv) meant to be loaded in the header. function all_js_to_footer() { remove_action('wp_head', ...


0

You'll want to make sure you're loading the form with AJAX enabled. I'm assuming that the the form is actually refreshing the entire page (hence the popup closing). If you enable AJAX, only the form should be refreshed and the popup's visibility should not be impacted.


0

I'll assume the html you posted is a template that is part of a theme or plugin where you can interact with the page loading routines. You do not need to load jQuery, it is already loaded by WordPress. Instead, you should leverage the script loading system. The third parameter in wp_enqueue_script states dependencies: my-app needs angular to be loaded, ...


0

To properly count paragraphs, and to be consistant, the best will be is to make use of raw post content, and then apply the wpautop filter to the raw content. This way, WordPress will handle all the variables which at the end will determine how paragraphs are build and displayed We can also look at a couple of other things to make this as reliable as ...


0

Have faith ;-) Unfortunately, your code ain't correct in multiple ways. It assumes that the content only consists of content enclosed by paragraphs and doesn't work correctly if not. This would be one solution: add_filter('the_content', 'prefix_insert_post_ads'); /** * Content Filter */ function prefix_insert_post_ads($content) { $insertion = ...


1

This line in functions.php is your problem: $cat_id = get_post_meta($_REQUEST['cat']); I think you are misunderstanding the purpose of the get_post_meta() function. It is designed to get metadata for a WordPress Post, not data from a POST request to the site. The first parameter of the get_post_meta() function is the $post_id, but since you are passing ...


0

Please add below code to bottom of your functions.php, I have replaced with your menu item ID function lidget_popup_link() { ?> <script type="text/javascript"> jQuery(window).load(function() { var width = "680", /* Enter popup window width here */ height = "480", /* Enter popup window height here */ menuItem = ...


1

You need to loop through your posts, and retrieve the metadata for each post. Add them to your array, and encode them to JSON. $posts = $query->get_posts(); foreach( $posts as &$thispost ) { // reference the current item $thispost->meta = get_post_meta( $thispost->ID ); } Now you got a WP_Post-Object, with all the post meta available at ...


3

PHP wp_enqueue_scripts is a good time to localize the data. Make sure you target your script and create a name for the object as well as passing an array of data. In this case twitter_settings is the object that will be created and will hold all the data. twitter_settings.tweets_widget_id will ultimately hold your $tweet. add_action( 'wp_enqueue_scripts', ...



Top 50 recent answers are included