<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>bavotasan.com &#187; way</title>
	<atom:link href="http://bavotasan.com/tag/way/feed/" rel="self" type="application/rss+xml" />
	<link>http://bavotasan.com</link>
	<description>by c.bavota</description>
	<lastBuildDate>Tue, 07 Feb 2012 15:42:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Use jQuery to Replace a Word with a Link</title>
		<link>http://bavotasan.com/2010/jquery-replace-word-with-link/</link>
		<comments>http://bavotasan.com/2010/jquery-replace-word-with-link/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 20:54:46 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[body]]></category>
		<category><![CDATA[footer]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[head]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Lt]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[piece]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[site]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[var]]></category>
		<category><![CDATA[way]]></category>
		<category><![CDATA[Word]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=2615</guid>
		<description><![CDATA[If you use a word multiple times on your site and you don&#8217;t feel like going through all your posts to replace every instance of it, you can use jQuery to search your page and do the replacing for you. I wanted to replace a word throughout an entire site with a link and all [...]]]></description>
			<content:encoded><![CDATA[<p>If you use a word multiple times on your site and you don&#8217;t feel like going through all your posts to replace every instance of it, you can use jQuery to search your page and do the replacing for you. I wanted to replace a word throughout an entire site with a link and all it took was a small piece of code. </p>
<p>If you don&#8217;t already have jQuery loaded into your page, include this before your closing <code>&lt;head&gt;</code>.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">'text/javascript'</span> src<span style="color: #339933;">=</span><span style="color: #3366CC;">'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></td></tr></table></div>

<p>That will load up jQuery from Google.</p>
<p>Now you just need to include this in your site&#8217;s footer, before the closing <code>&lt;body&gt;</code>. (Why in the footer? Because including your JavaScript after all of your code is the efficient way to do it.)</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> thePage <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  thePage.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>thePage.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/jQuery/ig</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'&lt;a href=&quot;http://jquery.com&quot;&gt;jQuery&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></td></tr></table></div>

<p>Since jQuery doesn&#8217;t have a core function for replacing text, we will use the JavaScript <code><a href="http://www.w3schools.com/jsref/jsref_replace.asp">replace()</a></code> function. The <code>i</code> after the slash makes the search and replace case-insensitive, and the <code>g</code> makes it global. </p>
<p>I have the script working on this page to replace every instance of the word jQuery with a link to the jQuery Web site.</p>
<p><script type="text/javascript">
(function($) {
  $(".posttop p").each(function() {
    $(this).html($(this).html().replace(/jQuery/ig, '<a href="http://jquery.com">jQuery</a>')); 
  });
})(jQuery)
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2010/jquery-replace-word-with-link/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>A Simple CSS Trick to Vertically Align Text</title>
		<link>http://bavotasan.com/2010/a-simple-css-trick-to-vertically-align-text/</link>
		<comments>http://bavotasan.com/2010/a-simple-css-trick-to-vertically-align-text/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 17:33:08 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Center]]></category>
		<category><![CDATA[Containers]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[DIGGING]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[fff]]></category>
		<category><![CDATA[line]]></category>
		<category><![CDATA[solution]]></category>
		<category><![CDATA[technique]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[trick]]></category>
		<category><![CDATA[way]]></category>
		<category><![CDATA[Width]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=2604</guid>
		<description><![CDATA[I was trying to vertically align text within a div container and it just wasn&#8217;t working for me. You would think that using vertical-align in your CSS would accomplish just that, but you would be wrong. I found a way to do it using three div containers and absolute positioning but I felt that was [...]]]></description>
			<content:encoded><![CDATA[<p>I was trying to vertically align text within a div container and it just wasn&#8217;t working for me. You would think that using <code>vertical-align</code> in your CSS would accomplish just that, but you would be wrong. I found a way to do it using three div containers and absolute positioning but I felt that was a little overkill for my purposes. </p>
<p>This was the box I was designing:</p>
<div style="width: 100px; height: 100px; background: #666; color: #fff; text-align: center; text-shadow: none;">Some Text</div>
<p>After doing a lot of digging around, I discovered that you could set the line-height of your text to be the same as the height of your div container and this is what you would get:</p>
<div style="width: 100px; height: 100px; background: #666; color: #fff; text-align: center; text-shadow: none; line-height: 100px;">Some Text</div>
<p>That did it. </p>
<p>Here is the CSS I used:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="css" style="font-family:monospace;">div<span style="color: #6666ff;">.container</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#666</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* where the magic happens */</span>
<span style="color: #00AA00;">&#125;</span></pre></div></td></tr></table></div>

<p>The only way this technique wouldn&#8217;t work for you was if you had text on two lines, then the second line would be 100 pixels below the first. Hmm&#8230; maybe I could figure out a solution to that one as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2010/a-simple-css-trick-to-vertically-align-text/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using Ajax with WordPress</title>
		<link>http://bavotasan.com/2010/using-ajax-with-wordpress/</link>
		<comments>http://bavotasan.com/2010/using-ajax-with-wordpress/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 18:53:53 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[feedback]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[look]]></category>
		<category><![CDATA[magazine]]></category>
		<category><![CDATA[mailing]]></category>
		<category><![CDATA[person]]></category>
		<category><![CDATA[way]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=2586</guid>
		<description><![CDATA[A little while back, I updated Magazine Basic and added the Ajax save function. When I uploaded it to WordPress to await approval, I received some feedback on how I could incorporate Ajax using the admin-ajax.php file instead of the sloppy way I had it coded. All of the core Ajax functions in WordPress rely [...]]]></description>
			<content:encoded><![CDATA[<p>A little while back, I updated Magazine Basic and added the Ajax save function. When I uploaded it to WordPress to await approval, I received some feedback on how I could incorporate Ajax using the <code>admin-ajax.php</code> file instead of the sloppy way I had it coded. All of the core Ajax functions in WordPress rely on <code>admin-ajax.php</code> and using it for custom scripts is extremely easy to implement. </p>
<p>Let&#8217;s take a look at all the pieces you need to get it working. In this example I will build a small mailing list function that will send out an email to the admin when a person clicks submit.</p>
<p>Here&#8217;s our form:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">&lt;form method=&quot;post&quot; id=&quot;mailinglist&quot; action=&quot;&quot;&gt;
	&lt;div id=&quot;message&quot;&gt;&lt;/div&gt;
	&lt;input type=&quot;text&quot; name=&quot;mailinglistemail&quot; id=&quot;mailinglistemail&quot; /&gt;
	&lt;input type=&quot;submit&quot; name=&quot;submit&quot; id=&quot;mailinglistsubmit&quot; value=&quot;Join&quot; /&gt;&lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> admin_url<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/wp-admin/images/wpspin_light.gif&quot; alt=&quot;&quot; class=&quot;ajaxsave&quot; style=&quot;display: none;&quot; /&gt;
&lt;/form&gt;</pre></div></td></tr></table></div>

<p>Here&#8217;s the jQuery:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglist&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglistemail&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglist #message&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Please enter your email address.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> email <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#mailinglistemail'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>email.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;@&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">||</span> email.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglist #message&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Please enter a valid email address.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
					action<span style="color: #339933;">:</span> <span style="color: #3366CC;">'join_mailinglist'</span><span style="color: #339933;">,</span>
					email<span style="color: #339933;">:</span> email
				<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
				jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglistsubmit&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.ajaxsave&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				jQuery.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;?php echo admin_url('admin-ajax.php'); ?&gt;&quot;</span><span style="color: #339933;">,</span> data<span style="color: #339933;">,</span>
				<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.ajaxsave&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglistsubmit&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglist #message&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
				<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> 
&nbsp;
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>Let me explain each part. </p>
<p>When a user clicks submit, we need to check that the email field is not empty. If it is empty, we let the user know by sending the &#8220;Please enter your email address.&#8221; message and we stop the form from being submitted by including the <code>return false;</code> line.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglistemail&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglist #message&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Please enter your email address.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></td></tr></table></div>

<p>Next, we&#8217;ll do a simple validation to make sure the email address actually contains the @ symbol and a period. If not, send an error message and return false.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> email <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#mailinglistemail'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>email.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;@&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">||</span> email.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglist #message&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Please enter a valid email address.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></td></tr></table></div>

<p>Once all that is done and everything is good, we can submit our form. This is where <code>admin-ajax.php</code> comes into play. When using <code>admin-ajax.php</code>, you need to include an action callback to make it work. Our callback is <code>join_mailinglist</code>. This is going to interact with our PHP to make everything work on the backend. Let&#8217;s create a data variable to store our action and our email value.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	action<span style="color: #339933;">:</span> <span style="color: #3366CC;">'join_mailinglist'</span><span style="color: #339933;">,</span>
	email<span style="color: #339933;">:</span> email
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>Now we will hide our submit button and have a loader graphic appear to let people know something is going on. Then will will use the jQuery <a href="http://api.jquery.com/jQuery.post/">.post</a> function to send everything out to the <code>admin-ajax.php</code> file. Once the function is complete and a response is given, the loader will disappear, the submit button will return and a success message, or error message will indicate what happened.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglistsubmit&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.ajaxsave&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
jQuery.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;?php echo admin_url('admin-ajax.php'); ?&gt;&quot;</span><span style="color: #339933;">,</span> data<span style="color: #339933;">,</span>
<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.ajaxsave&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglistsubmit&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglist #message&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>With the form and the jQuery in place, all we need now is some PHP. </p>
<p>The <code>admin-ajax.php</code> file requires two action filters.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_ajax_my_action'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_action_callback'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_ajax_nopriv_my_action'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_action_callback'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>The first action will only work if users are logged in. The second is if users don&#8217;t have to be logged in. For our requirements, it should look like this:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_ajax_join_mailinglist'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'join_mailinglist_callback'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_ajax_nopriv_join_mailinglist'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'join_mailinglist_callback'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>Here is our join_mailinglist_callback function, which needs to be added to <code>functions.php</code>:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> join_mailinglist_callback<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$yourEmail</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'c@bavotasan.com'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Add me to your mailing list'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$success</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$yourEmail</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$success</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Your email is subscribed to our mailing list.'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'There was a problem. Please try again.'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></td></tr></table></div>

<p>With everything in place, you will get a form that works like the one below.</p>
<form method="post" id="mailinglist" action="">
<div id="message"></div>
<input type="text" name="mailinglistemail" id="mailinglistemail" />
<input type="submit" name="submit" id="mailinglistsubmit" value="Join" /><img src="http://bavotasan.com/wp-admin/images/wpspin_light.gif" alt="" class="ajaxsave" style="display: none;" /><br />
</form>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2010/using-ajax-with-wordpress/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Great Font Resources for Web Development</title>
		<link>http://bavotasan.com/2010/great-font-resources/</link>
		<comments>http://bavotasan.com/2010/great-font-resources/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 14:20:25 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[APIs]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[face kits]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[Fonts]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[Squirrel]]></category>
		<category><![CDATA[text elements]]></category>
		<category><![CDATA[Tool]]></category>
		<category><![CDATA[type]]></category>
		<category><![CDATA[way]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=2517</guid>
		<description><![CDATA[Ever since I wrote Embedding Fonts in your Web Site with CSS and @font-face many people have been emailing me with questions about adding new fonts to their sites. One of the easiest ways is with The New Google Font API but there are also a few others resources available. Here is a list of [...]]]></description>
			<content:encoded><![CDATA[<p>Ever since I wrote <a href="http://bavotasan.com/tutorials/embedding-fonts-web-site-css-font-face/">Embedding Fonts in your Web Site with CSS and @font-face</a> many people have been emailing me with questions about adding new fonts to their sites. One of the easiest ways is with <a href="http://bavotasan.com/articles/google-font-api/">The New Google Font API</a> but there are also a few others resources available. Here is a list of places to find fonts and tools you can use to include them in your Web site.</p>
<h3>Font Squirrel</h3>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/07/fontsquirrel.jpg" alt="Font Squirrel" title="fontsquirrel" width="550" height="160" class="alignleft size-full wp-image-2572" /><br />
Font Squirrel has an amazing library of free commercial-use fonts. All of the @font-face kits that are available in my <a href="http://themes.bavotasan.com/category/premium-themes/">Premium themes</a> come from Font Squirrel. You can download fonts to use in desktop publishing or you can grab some @font-face kits to use on your Web site. There is even a handy, simple to use tool for converting standard fonts into @font-face kits for embedding on your Web site.<br />
<a href="http://www.fontsquirrel.com/">http://www.fontsquirrel.com/</a></p>
<h3>Google Font API</h3>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/07/googlefont.jpg" alt="Google Font API" title="googlefont" width="550" height="160" class="alignleft size-full wp-image-2564" /><br />
I wrote about this one already so just check out <a href="http://bavotasan.com/articles/google-font-api/">that article</a>.</p>
<h3>TypeKit</h3>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/07/typekit.jpg" alt="TypeKit" title="typekit" width="550" height="160" class="alignleft size-full wp-image-2567" /><br />
TypeKit is a subscription-based service that allows you to link to fonts from many different type foundries. Subscription costs range from free to $99.99 per year. A free account allows for 25,000 pageviews a month and a limit of 2 fonts throughout you site. It is a great way to test out the service to see if it is right for you.<br />
<a href="https://typekit.com/">https://typekit.com/</a></p>
<h3>WebFont Loader</h3>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/07/webfont.jpg" alt="WebFont Loader" title="webfont" width="550" height="160" class="alignleft size-full wp-image-2565" /><br />
This one is very similar to the Google Font API but it offers a wider range of resources of available fonts. You can use Google Fonts, TypeKit, Ascender or custom fonts.<br />
<a href="http://code.google.com/apis/webfonts/docs/webfont_loader.html">http://code.google.com/apis/webfonts/docs/webfont_loader.html</a></p>
<h3>sIFR</h3>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/07/sifr.jpg" alt="sIFR" title="sifr" width="550" height="160" class="alignleft size-full wp-image-2575" /><br />
sIFR (Scalable Inman Flash Replacement) is an open source piece of JavaScript that allows you to replace text elements on your Web site with Flash embedded equivalents. It is a bit more complicated to implement but there are many sites that use it and the results are quite nice.<br />
<a href="http://wiki.novemberborn.net/sifr3/">http://wiki.novemberborn.net/sifr3/</a></p>
<h3>typeface.js</h3>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/07/typeface.jpg" alt="typeface.js" title="typeface" width="550" height="160" class="alignleft size-full wp-image-2576" /><br />
typeface.js was developed by David Chester as an alternative to using Flash to embed fonts on your site. Using typeface.js is pretty straightforward, since all it takes is the core JavaScript file and then a font. You can even convert your own fonts.<br />
<a href="http://typeface.neocracy.org/">http://typeface.neocracy.org/</a></p>
<h3>FLIR</h3>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/07/flir.jpg" alt="FLIR" title="flir" width="550" height="160" class="alignleft size-full wp-image-2577" /><br />
FLIR (FaceLift Image Replacement) is another alternative to sIFR. It was created by Cory Mawhorter and uses JavaScript and PHP to dynamically create images of the text elements that you wish to use specific fonts on. Implementing it requires only a few lines of code and you are up and running.<br />
<a href="http://facelift.mawhorter.net/">http://facelift.mawhorter.net/</a></p>
<h3>Cufón</h3>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/07/cufon.jpg" alt="Cufón" title="cufon" width="550" height="160" class="alignleft size-full wp-image-2578" /><br />
Cufón works with a rendering engine built in JavaScript and a font generator that uses <a href="http://fontforge.sourceforge.net/">FontForge</a> to convert fonts to a proprietary format.<br />
<a href="http://wiki.github.com/sorccu/cufon/">http://wiki.github.com/sorccu/cufon/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2010/great-font-resources/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>6 Tips to Speed Up jQuery</title>
		<link>http://bavotasan.com/2010/tips-speed-up-jquery/</link>
		<comments>http://bavotasan.com/2010/tips-speed-up-jquery/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 16:10:12 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[attr]]></category>
		<category><![CDATA[call]]></category>
		<category><![CDATA[Click]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[element]]></category>
		<category><![CDATA[Elements]]></category>
		<category><![CDATA[fff]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[img]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Location]]></category>
		<category><![CDATA[Padding]]></category>
		<category><![CDATA[Properties]]></category>
		<category><![CDATA[selector]]></category>
		<category><![CDATA[use]]></category>
		<category><![CDATA[way]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=2518</guid>
		<description><![CDATA[As it stands, jQuery is an amazingly efficient JavaScript framework, but there are a few things that you can do when creating your code that will end up slowing it down significantly. I&#8217;ve noticed that a few small changes to my standard way of using jQuery have made my code run a lot faster. 1. [...]]]></description>
			<content:encoded><![CDATA[<p>As it stands, <a href="http://jquery.com/">jQuery</a> is an amazingly efficient JavaScript framework, but there are a few things that you can do when creating your code that will end up slowing it down significantly. I&#8217;ve noticed that a few small changes to my standard way of using <a href="http://jquery.com/">jQuery</a> have made my code run a lot faster.</p>
<h3>1. Be More Specific with Selectors</h3>
<p>When you are setting up <a href="http://jquery.com/">jQuery</a> to search through the DOM for a specific element, the more information you give it, the faster it will find the element. It is also faster to use IDs instead of classes.</p>
<p>Something like this will require going through the whole DOM structure to find the element:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.item&quot;</span><span style="color: #009900;">&#41;</span></pre></div></td></tr></table></div>

<p>These are way more efficient:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#item&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// use IDs instead of Classes</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;p.first .item&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// be more specific with the location</span></pre></div></td></tr></table></div>

<h3>2. Always Use $(this)  </h3>
<p>If you are using a selector to traverse the DOM in search of an element to perform a specific function on, that element becomes stored and can be manipulated within the function by using <code>$(this)</code>.</p>
<p>This code will traverse the DOM twice to get the same element:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#item&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#item&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'clicked'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>This is the efficient way since the element is already stored within the <code>$(this)</code> call:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#item&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'clicked'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<h3>3. Pass Multiple Selectors</h3>
<p>If you want the same functions to occur on multiple elements, it is possible to group selectors together to increase performance and avoid repetitive traversing of the DOM.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// bad</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;p#one&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;p#two&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;p#three&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>


<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// good</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;p#one, p#two, p#three&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<h3>4. Use Multiple Properties and Values</h3>
<p>Many <a href="http://jquery.com/">jQuery</a> methods accept multiple properties and values instead of just a single property and value pair. Including multiple properties will help speeds things up as it reduces the amount of <a href="http://jquery.com/">jQuery</a> objects that are created within your code.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// bad</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;img#one&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'src'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'http://mysite.com/images/image.jpg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;img#one&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'alt'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'My Image'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>


<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// good</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;img#one&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #3366CC;">'src'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'http://mysite.com/images/image.jpg'</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">'alt'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'My Image'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<h3>5. Add Styles with Classes or IDs</h3>
<p>If you want to add multiple style changes to an element, it make more sense to use CSS to assign your styles to a Class or ID, and then add that Class or ID to the element. </p>
<p>Create your styles:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="css" style="font-family:monospace;">&lt;style type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #00AA00;">&gt;</span>
.<span style="color: #993333;">faster</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#dd0000</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span> <span style="color: #933;">8px</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&lt;/style<span style="color: #00AA00;">&gt;</span></pre></div></td></tr></table></div>

<p>And instead of doing this:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;p&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #3366CC;">'background'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'#dd0000'</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">'color'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'#fff'</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">'padding'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'5px 8px'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>Do this:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;p&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;faster&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<h3>6. Use Chaining</h3>
<p>Once you have already selected an element, you can chain your commands using <code>.end()</code> instead of traversing the DOM multiple times to find the same element. Understanding chaining might take a bit of trial and error to really get the hang of it. Certain commands require that you <code>.end()</code> the chain and certain don&#8217;t. I&#8217;ll give more in depth tutorial on chaining in the future to help guide you through the ins and outs of it all.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//bad</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;div&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;div p.one&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;div p.two&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'highlight'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>


<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//good</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;div&quot;</span><span style="color: #009900;">&#41;</span>
  .<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  .<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'p.one'</span><span style="color: #009900;">&#41;</span>
  .<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
.<span style="color: #660066;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  .<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'p.two'</span><span style="color: #009900;">&#41;</span>
  .<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'highlight'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>These are just a few things that have helped me make my <a href="http://jquery.com/">jQuery</a> code run more efficiently. There are tons of books and resources out there that can help you take it to the next level to create the most efficient <a href="http://jquery.com/">jQuery</a> code imaginable. Here are a few I suggest:</p>
<ul>
<li><a href="http://jqueryenlightenment.com/">jQuery Enlightenment by Cody Lindley</a></li>
<li><a href="http://www.learningjquery.com/">Learning jQuery</a></li>
<li><a href="http://jqueryfordesigners.com/">jQuery for Designers</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2010/tips-speed-up-jquery/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Creating a Scrolling Back to Top Button with jQuery</title>
		<link>http://bavotasan.com/2010/scrolling-back-to-top-button-jquery/</link>
		<comments>http://bavotasan.com/2010/scrolling-back-to-top-button-jquery/#comments</comments>
		<pubDate>Mon, 28 Jun 2010 20:55:39 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[anchor]]></category>
		<category><![CDATA[animate]]></category>
		<category><![CDATA[body]]></category>
		<category><![CDATA[button]]></category>
		<category><![CDATA[Click]]></category>
		<category><![CDATA[Creating]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[hundred times]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[Lt]]></category>
		<category><![CDATA[name]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[span]]></category>
		<category><![CDATA[tag]]></category>
		<category><![CDATA[version]]></category>
		<category><![CDATA[way]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=2234</guid>
		<description><![CDATA[If you take a look way, way, way down at the bottom of this page, you will see a Back to Top button that scrolls the whole page until it reaches to top. It is a pretty simple effect to add to your site and looks a hundred-times cooler than just using your typical anchor [...]]]></description>
			<content:encoded><![CDATA[<p>If you take a look way, way, way down at the bottom of this page, you will see a Back to Top button that scrolls the whole page until it reaches to top. It is a pretty simple effect to add to your site and looks a hundred-times cooler than just using your typical anchor name and link. Getting it all to work takes nothing more than a few lines of <a href="http://jquery.com/">jQuery</a> version 1.4.2.<br />
<span id="more-2234"></span><br />
First, we need to create our button/link. I am just going to use an anchor tag and some text:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;javascript:void(0)&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;backtotop&quot;</span><span style="color: #339933;">&gt;</span>Back to Top<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span></pre></div></td></tr></table></div>

<p>Next we need to add some <a href="http://jquery.com/">jQuery</a> between the <code>&lt;head&gt;</code> tags:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">'text/javascript'</span> src<span style="color: #339933;">=</span><span style="color: #3366CC;">'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">'text/javascript'</span><span style="color: #339933;">&gt;</span>
jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.backtotop'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'html, body'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>scrollTop<span style="color: #339933;">:</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></td></tr></table></div>

<p>Remember, you can change the speed by replacing <code>slow</code> with a numerical value. You can also add some easing effects by including the <a href="http://jqueryui.com/">jQuery UI</a>. Read more about easing effects <a href="http://jqueryui.com/demos/effect/#easing">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2010/scrolling-back-to-top-button-jquery/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Tables and Borders</title>
		<link>http://bavotasan.com/2010/tables-and-borders/</link>
		<comments>http://bavotasan.com/2010/tables-and-borders/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 16:38:08 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[bit]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[Easy Solution]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[look]]></category>
		<category><![CDATA[Luckily]]></category>
		<category><![CDATA[order]]></category>
		<category><![CDATA[parameter]]></category>
		<category><![CDATA[solution]]></category>
		<category><![CDATA[something]]></category>
		<category><![CDATA[Style]]></category>
		<category><![CDATA[table]]></category>
		<category><![CDATA[way]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=1827</guid>
		<description><![CDATA[I have had a few people ask me, &#8220;How come when I create a table and set the border parameter to 1 it doesn&#8217;t actually display any borders?&#8221; Well, the answer is usually that there may be some CSS that overwrites that parameter by establishing a style that removes all borders from tables. Luckily, there [...]]]></description>
			<content:encoded><![CDATA[<p>I have had a few people ask me, &#8220;How come when I create a table and set the border parameter to 1 it doesn&#8217;t actually display any borders?&#8221; Well, the answer is usually that there may be some CSS that overwrites that parameter by establishing a style that removes all borders from tables. Luckily, there is an easy solution.<br />
<span id="more-1827"></span><br />
Let&#8217;s take a look at some examples.</p>
<p>Adding something like this:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="css" style="font-family:monospace;">table <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></td></tr></table></div>

<p>will only add a border around the table. You would then need something like this:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="css" style="font-family:monospace;">table td<span style="color: #00AA00;">,</span> table th <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></td></tr></table></div>

<p>That will add borders around your <em>th</em> cells and your <em>td</em> cells, but now you will probably have your borders doubling up. It might look something like this:</p>
<table class="allborders" cellpadding="5" cellspacing="0" border="0">
<tr>
<th>Header one</th>
<th>Header two</th>
<th>Header three</th>
</tr>
<tr>
<td>Something here</td>
<td>Another thing here</td>
<td>Something else here</td>
</tr>
</table>
<p>Here I added some cellspacing so you can see all the borders:</p>
<table class="allborders" cellpadding="5" cellspacing="5" border="0">
<tr>
<th>Header one</th>
<th>Header two</th>
<th>Header three</th>
</tr>
<tr>
<td>Something here</td>
<td>Another thing here</td>
<td>Something else here</td>
</tr>
</table>
<p>In order to get the table border back to the way it would have been if border=&#8221;1&#8243; would have worked requires an extra style in your CSS.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="css" style="font-family:monospace;">table <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border-collapse</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">collapse</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></td></tr></table></div>

<p>Now your table should look like this:</p>
<table class="goodborders" cellpadding="5" cellspacing="0" border="0">
<tr>
<th>Header one</th>
<th>Header two</th>
<th>Header three</th>
</tr>
<tr>
<td>Something here</td>
<td>Another thing here</td>
<td>Something else here</td>
</tr>
</table>
<p>Read a bit more about it <a href="http://www.w3schools.com/css/pr_tab_border-collapse.asp">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2010/tables-and-borders/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Clever and Safe Way to Display your Email Address</title>
		<link>http://bavotasan.com/2009/a-clever-and-safe-way-to-display-your-email-address/</link>
		<comments>http://bavotasan.com/2009/a-clever-and-safe-way-to-display-your-email-address/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 01:31:14 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[contact]]></category>
		<category><![CDATA[direction]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[reason]]></category>
		<category><![CDATA[span]]></category>
		<category><![CDATA[Style]]></category>
		<category><![CDATA[Stylesheet]]></category>
		<category><![CDATA[way]]></category>
		<category><![CDATA[Web Page]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=1602</guid>
		<description><![CDATA[There are many reason why you shouldn&#8217;t place your email address on a Web page; the number one being spambots. There are tons a spambots running around the Web looking for that &#8220;@&#8221; symbol so that they can bombard you with as much spam as possible. Instead of displaying my email address, I use a [...]]]></description>
			<content:encoded><![CDATA[<p>There are many reason why you shouldn&#8217;t place your email address on a Web page; the number one being spambots. There are tons a spambots running around the Web looking for that &#8220;@&#8221; symbol so that they can bombard you with as much spam as possible.<span id="more-1602"></span> Instead of displaying my email address, I use a contact form. Lately though, I have been reading about many reasons why you should display your email address so that it is easier for visitors to contact you.</p>
<p>Here is a clever and safe way to display your email address using CSS redirection.</p>
<p>First we need to create a style in your header or in your stylesheet:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="css" style="font-family:monospace;">&lt;style type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #00AA00;">&gt;</span>
span<span style="color: #6666ff;">.redirect</span> <span style="color: #00AA00;">&#123;</span> 
<span style="color: #000000; font-weight: bold;">unicode-bidi</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bidi-override</span><span style="color: #00AA00;">;</span> 
<span style="color: #000000; font-weight: bold;">direction</span><span style="color: #00AA00;">:</span> rtl<span style="color: #00AA00;">;</span> 
<span style="color: #00AA00;">&#125;</span>
&lt;/style<span style="color: #00AA00;">&gt;</span></pre></div></td></tr></table></div>

<p>Now all you need to do is write your email address backwards and use the style like this:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>span <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;redirect&quot;</span><span style="color: #339933;">&gt;</span>moc<span style="color: #339933;">.</span>liamg<span style="color: #339933;">@</span>emanruoy<span style="color: #339933;">&lt;/</span>span<span style="color: #339933;">&gt;</span></pre></div></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2009/a-clever-and-safe-way-to-display-your-email-address/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Using PHP to Remove an HTML Tag from a String</title>
		<link>http://bavotasan.com/2009/using-php-to-remove-an-html-tag-from-a-string/</link>
		<comments>http://bavotasan.com/2009/using-php-to-remove-an-html-tag-from-a-string/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 21:54:49 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[Image Tag]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[Php Function]]></category>
		<category><![CDATA[piece]]></category>
		<category><![CDATA[Preg]]></category>
		<category><![CDATA[Remove]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[tag]]></category>
		<category><![CDATA[way]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=1555</guid>
		<description><![CDATA[There are times when you need to strip one specific HTML tag from a string and the PHP function strip_tags() doesn&#8217;t work the way you want it to. strip_tags() allows for certain exclusions, but why would you use that when you only want to exclude one tag and include all other tags? Especially when you [...]]]></description>
			<content:encoded><![CDATA[<p>There are times when you need to strip one specific HTML tag from a string and the PHP function <code>strip_tags()</code> doesn&#8217;t work the way you want it to.  <code>strip_tags()</code> allows for certain exclusions, but why would you use that when you only want to exclude one tag and include all other tags? Especially when you can use <code>preg_replace()</code>.<br />
<span id="more-1555"></span><br />
Here is a quick little piece of code that can be modified for any specific HTML tag you want to remove from a string. I am using it below to remove an image tag.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Here is your content with an image tag &lt;img src=&quot;http://bavotasan.com/wp-content/themes/bavotasan_new/images/bavota.png&quot; alt=&quot;Image&quot; /&gt;'</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&lt;img[^&gt;]+\&gt;/i&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$string</span> <span style="color: #666666; font-style: italic;">// will output &quot;Here is your content with an image tag&quot; without the image tag</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></td></tr></table></div>

<p>You can replace the <code>img</code> in the <code>preg_replace()</code> function for it to work with whichever HTML tag you wish.</p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2009/using-php-to-remove-an-html-tag-from-a-string/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Check if a Page is a Child of Another Page in WordPress</title>
		<link>http://bavotasan.com/2009/check-if-a-page-is-a-child-of-another-page-in-wordpress/</link>
		<comments>http://bavotasan.com/2009/check-if-a-page-is-a-child-of-another-page-in-wordpress/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 17:11:26 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[default]]></category>
		<category><![CDATA[Directory]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[parent]]></category>
		<category><![CDATA[Place]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[return]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[way]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=1456</guid>
		<description><![CDATA[This post has been updated in &#8220;is_child() Conditional Function for WordPress&#8221;. WordPress has some default conditional tags that are really helpful when developing themes and plugins that need specific functions on specific pages. Strange enough though, there is no way to check if a page is a child of another page. This small function checks [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://bit.ly/dOxWm7">This post has been updated in &#8220;is_child() Conditional Function for WordPress&#8221;.</a></p>
<p>WordPress has some default <a href="http://codex.wordpress.org/Conditional_Tags">conditional tags</a> that are really helpful when developing themes and plugins that need specific functions on specific pages. Strange enough though, there is no way to check if a page is a child of another page.<br />
<span id="more-1456"></span><br />
This small function checks the database to see if the page happens to have a parent page assigned to it. If so, then the function will return true.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> is_child<span style="color: #009900;">&#40;</span><span style="color: #000088;">$pageID</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$post</span><span style="color: #339933;">;</span> 
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> is_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_parent</span><span style="color: #339933;">==</span><span style="color: #000088;">$pageID</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
               <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> 
               <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></td></tr></table></div>

<p>Place the above code in your theme&#8217;s functions.php file, or create a functions.php file and place it in your theme&#8217;s directory. Then you can use the is_child() function anywhere in your theme. Your code would look something like this:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>is_child<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">343</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;This is a child page of 'The Parent Page Title'.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2009/check-if-a-page-is-a-child-of-another-page-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
	</channel>
</rss>

