APPLYING SPAN TO THE FIRST LETTER OF EVERY WORD IN A SENTENCE
Check out @ http://pastebin.com/ij6xeeGT
For javascript substring reference: http://www.w3schools.com/jsref/jsref_substring.asp
Check out @ http://pastebin.com/ij6xeeGT
For javascript substring reference: http://www.w3schools.com/jsref/jsref_substring.asp
Here are some wordpress snippet and hacks which are very useful for admin side.
Very often in coding for wordpress I want to use some php vars in javascript (saved options, userinfo, etc) for that I end up
1) Naming my js file as “filename.js.php” now it becomes a php(js) file the only problem is for this file wordpress environment is not loaded so I load wordpress environment using “include ‘/path/to/wp-load.php’”. While some may think this is ok, so what we if have to load wordpress for this file, is makes my work easy, but then again we have to switch between php code block and javascript block.
2) Embedding javascript in the body section of the the code where i need to use some php variable in javascript. While this might be the easiest way it makes code debugging and maintaining a very tedious task.
Now for the solution, wordpress provides a function “wp_localize_script” that is supposed to be used in conjunction with wp_enqueue_script() function. Heres the link to read more..
Another option is putting the following code in head section of the wordpress using wp_print_script/admin_print_script
<script type="text/javascript">
// <![CDATA[
var someSettings = {
'nonce': '<?php echo wp_create_nonce('nonce-string'); ?>',
'ajax_url': '<?php echo admin_url('admin-ajax.php); ?>'
};
// ]]>
</script>
[Actually this is what wordpress does with wp_localize_script
. This is usefull when creating iframes]
now these values can be used in your javascript code like so
var nonce = someSettings.nonce;
var ajax_url = someSettings.ajax_url;
Happy coding…
I’ve used it and its very nice. we shouldn’t use *.js.php
Heres how to decode php encoded html string in javascript without actually using any function.
for jQuery :
var decoded_string = jQuery(“<div />”).html(encoded_string).text();
TADA… thats it.
Most of u might be following CSS-Tricks
but u can also check this code-snippets feed
http://feeds.feedburner.com/CSS-TricksSnippets
Its very useful.
You can see same section on web here
I will be using it in the very near future.