Hot answers tagged javascript
6
I formatted that code as best I could, and once formatted it is obviously very broken. wp_enqueue_script takes 5 parameters. You have 9. And several of the first five are wrong. I expect that you would see errors if you had debugging enabled.
You seem to be trying to enqueue all of your scripts in the same wp_enqueue_script. You can't do that. Perhaps that ...
3
As a corollary to @s_ha_dum's answer, you could also register scripts with hierarchically declared dependencies, and then just enqueue your ultimate script. Something like so:
function add_my_script() {
// Register first script, dependent on jQuery
wp_register_script(
'imagesLoaded',
get_template_directory_uri() . ...
2
You can store the data in the user meta as an array of post-id -> comment count at last visit and then simply count the comments since that date, for example
function get_user_comment_count_since_last_visit($user_id ,$post_id){
//only do this for logged in users
if ($user_id <= 0 ){
return 0;
}
/**
* get last comment count ...
1
You should use wp_enqueue_script for your javascript files instead of adding the code directly into the post content.
ps:
You can check out the callbacks on the the_content filter, using
add_action('wp_footer',function(){
global $wp_filter;
printf('<pre>%s</pre>',print_r( $wp_filter['the_content'],true));
});
to display them ...
1
The CSS is in wp-admin/css/colors-classic.css and wp-admin/css/colors-fresh.css and the min versions of those, including the icons32-2x.png ones. I can see them when I grep the directory. For example, wp-admin/css/colors-classic.css:2162.
The images themselves are in wp-admin/images, as you can see from the style rules, but you should not be ...
1
Use wp_localize_script
function set_js_var() {
$translation_array = array( 'blog_name' => get_bloginfo('name') );
wp_localize_script( 'jquery', 'my_data', $translation_array );
}
add_action('wp_enqueue_scripts','set_js_var');
If you look at the source of the page you will see something like:
<script type='text/javascript'>
/* <![CDATA[ */
...
1
I'm not sure this is a real answer, but have you tried PHP-markdown-extra (by the very same Michel Fortin)?
At least for me (using Mark Jaquith's markdown-on-save plugin) your example is not a problem.
But Markdown-extra is not perfect either and I've seen some other quirks with respect to emphasis, e.g. Let $(y_n)_{n\in \omega}$ enumerate ${ x_i: i \in ...
1
The best way to do this is to use wp_localize_script(), it serves exactly the purpose you are mentioning: passing strings to Javascript from PHP. You can do all sorts of interesting things with that: as a rule of thumb, use that when you want PHP to communicate with Javascript.
In your case you want something like this:
$ritc = array( 'initialize' => ...
1
This is in wp-admin/js/common.js or wp-admin/js/common.min.js:
// Scroll into view when focused
$('#contextual-help-link, #show-settings-link').on( 'focus.scroll-into-view', function(e){
if ( e.target.scrollIntoView )
e.target.scrollIntoView(false);
});
Found with a search for show-settings-link in the complete source. :)
Only top voted, non community-wiki answers of a minimum length are eligible