Stopping the auto-formatting madness

So I put in this donation form on a page and WordPress reformats it.  A <br /> tag was inserted between a dollar sign ($) and the input field tag for the amount so the $ appears above the box on the published page.

A Google search brought me to this post which suggests a way to disable all the auto-formatting for a page or post.  That’s a little extreme for me because that would require me to reformat the whole site or a little coding on my part to say I just wanted auto-formatting turned off for that particular page.

I wanted something simpler and found it with the WP-No-Format plugin. By using a couple lines of code, I can shield select parts of my text from auto-formatting by placing <!– noformat on –-> and <!– noformat off –-> around the code I want to protect.

I love the plug-ins that do one thing and do them well.

If you like the WP-No-Format plugin, why not send the author a donation? Great work like this that saves us time should be rewarded.

Taming Multiple Loops

So I’m calling a second query inside the Loop, but after the second query ends, the primary loop should take over, right?  Not in this case.

Turned out I needed to call the function wp_reset_query(); after the secondary loop.

Here was my setup: in the page.php template, I wanted a sidebar that displayed the content of another page.  The reason is some pages will need to have the same information displayed on the side, and I wanted to be able to control this on a per page basis. (There is probably a plugin for this, but programming is so much more fun.)

So in the page editor, I set up a custom meta called “sidebar-post” and set it to the path of the page I wanted to be displayed. Back in the page.php template, I set up the WP_Query call like so:

     $sidebar_post = get_post_meta($post->ID, ‘sidebar-post’, false);
     foreach ($sidebar_post as $sidebar_postitem) {
          $sidebar_querystring = ‘pagename=’.$sidebar_postitem;
          $sidebar_query = new WP_Query($sidebar_querystring);
          while ($sidebar_query->have_posts()) : $sidebar_query->the_post(); 
               the_content();
          endwhile;
     }

I set up the code so if I wanted to, I could show more than one page. Now I was able to get this page to display in the sidebar just fine, but page contents appeared again where the primary page content was supposed to be.

I tried a trick described here under the “Multiple Loops Example 2” where you set the primary query to a temporary variable, then set it back after the secondary loop.

     <?php $temp_query = $wp_query; ?>

     <!–  secondary loop processing //—>

     <?php $wp_query = $temp_query; ?>

But that didn’t work.  The secondary query was still in control.

So after some searching I found the wp_reset_query(); function which “destroys the previous query used on a custom Loop”.

So now my code looked like this:

     $sidebar_post = get_post_meta($post->ID, ‘sidebar-post’, false);
     foreach ($sidebar_post as $sidebar_postitem) {
          $sidebar_querystring = ‘pagename=’.$sidebar_postitem;
          $sidebar_query = new WP_Query($sidebar_querystring);
          while ($sidebar_query->have_posts()) : $sidebar_query->the_post(); 
               the_content();
          endwhile;
     }
     wp_reset_query();

And, just as advertised, it killed the secondary loop query and the primary content was displaying properly.

On a side note, I am planning on getting this work with both pages and posts.

Is “site” a reserved word?

I have 2 WordPress installs on the same domain and server. Custom (pretty) permalinks worked on one, but not the other. Domain names have been changed to protect the innocent. 

I have:
http://www.mysite.com/site
which is in development. And
http://www.mysite.com/wordpress
which has been around for a while.

Both have the custom permalink setting of /%category%/%postname%/

/site gives me a 404 error.
/wordpress works fine.

Their .htaccess files are identical except that /wordpress’s says "wordpress" where /site’s says "site".

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /site/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site/index.php [L]
</IfModule>

# END WordPress

The server is a Deluxe Linux server on Godaddy.

I followed the standard method of waiting after setting up the permalinks on a Godaddy server. I waited for days and /site still did not work.

/wordpress did not have the custom permalinks on yet.  It started working immediately after switching. (I think there may have been an existing empty .htaccess file.)

So, same versions of WordPress, same Linux server, similar setup, no weird plugins, same .htaccess file, same database with different prefixes for the tables.

I have tried reinstalling /site using the built-in updater.  I even tried deleting the database tables and uploading a fresh install of WordPress.

Then I had the idea to rename the "site" folder thinking maybe "site" was a reserved word or something.  So I went into the General settings, changed the paths to http://www.mysite.com/web, saved changes, and used FTP to change the folder name from "site" to "web".

It worked.

Even the .htaccess file was automatically changed.

Just to be sure, I changed "web" back to "site" and the permalinks stopped working until I changed it back to "web".

Does anyone have any insight?  Is this a WordPress, Apache, or a Godaddy thing?

Postie 1.3.2 and WordPress MU

There is a problem with Postie 1.3.2 and WordPress MU.

On the blogs within my installation of WordPress MU, I would get this error when I went to the backend of the blogs that had Postie 1.3.2 activated:

Fatal error: Call to undefined function wp_get_current_user() in /<install path>/wp-includes/capabilities.php on line 920

The quickest fix was to use FTP to delete the plugin and replace it with the earlier version of Postie (1.3.1).  You can get it here:
http://wordpress.org/extend/plugins/postie/download/

I activated Postie 1.3.1 and everything seemed to be OK.

Now I just have to remember not to update the plugin until the issue is resolved.

Update: The text of the message is coming through, but it drops the subject.  It was adding “(via Postie)” until I deactivated the Postie Filter plugin. Anyone know why it’s doing this?  Please comment.

XML Sitemap Generator Plugin for WordPress error

I hate SEO.

Hate it.

Hate it to death.

But it’s a necessary evil so I have to deal.

So I am very happy when I can find plugins that will do a lot of  the work for me.

One such plugin is the popular All In One SEO.

Another is the XML Sitemap Generator Plugin for WordPress which does just as the name implies: it generates an XML sitemap for your WordPress site. An XML sitemap helps search engines crawl through your site more thoroughly. The plugin can be configured to notify various search engines of changes to your site so they will queue up your site to get crawled again to find and index the new content.  You can also add the XML sitemap URL to your Google Webmaster Tools account.

After installing the plugin I kept getting an error when I tried to manually create a sitemap:

There was a problem writing your sitemap file. Make sure the file exists and is writable.

Note: I’m running WordPress on a Deluxe Windows Hosting account at Godaddy.com

I checked to make sure the folders and files had writable permissions and they did.

Then I noticed the setting on the plugin config page called “Location of your map file”.  I wondered if the plugin was having trouble finding the proper location to write the file.

The location setting was on “Automatic” so I switched it to “Custom location” and entered the relative path where I thought the file should be.  No good.

The “Custom location” also takes an absolute path.  Using an absolute path might come back to bite me later should the server change, but I wanted to make sure this worked.  So I wrote a quick PHP script to find the absolute path of my site root (where the sitemap XML should be located):

<?php
echo realpath(“index.php”);
?>

Realpath is a PHP function that retrieves the absolute path of the specified file.

I uploaded the PHP file to the root folder of my blog and ran it on the site.  I then copied and pasted the path into the Custom Path setting.

And it didn’t work.

I gave up for the day.  I came back today to try to fix the problem and found there was an update for that plugin that was available (3.1.6 as of this writing).  I updated the plugin, and it worked!

I’m not 100% it was the update that fixed it, but it’s working now.

Just to be sure, I switched it back to the “Automatic Detection” setting.  It failed.  Switching it back to Custom worked fine.

WordPress email and Godaddy part 2

The SMTP plugin doesn’t seem to like it when you put a Gmail address in the From field… or maybe Gmail doesn’t like being used in WordPress.  Hmm…

Anyway, I created an email address using one of my many Godaddy email hosting credits, forwarded the email to my Gmail, and put that email in the From field.  Worked fine (test returned "true" instead of "false").

Be sure to read Part 1 here.

Update 2009-08-28: While Gmail addresses do not seem to work in the From field, Google Apps email address do!

Pretty Permalinks with Godaddy Windows Hosting

Want pretty permalinks in WordPress?  Who wouldn’t?

However, if you are hosting your WordPress blog on a Godaddy Windows server, you need to one extra step to make this happen:

Copy and paste the following into a text file, save as “web.config”, and upload to the root of your WordPress blog.  If you already have a web.config file, be careful to just copy  the <rewrite>…</rewrite> tags and everything between them then paste inbetween the <system.webserver>…</system.webserver> tags.

<?xml version="1.0"?>
<configuration>
   <system.webServer>
      <rewrite>
         <rules>
            <rule name="Main Rule" stopProcessing="true">
               <match url=".*" />
               <conditions logicalGrouping="MatchAll">
                 <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                 <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
               </conditions>
               <action type="Rewrite" url="index.php" />
            </rule>
         </rules>
      </rewrite>
   </system.webServer>
</configuration>

See the original info here: http://learn.iis.net/page.aspx/466/enabling-pretty-permalinks-in-wordpress/

Aweber adds tags to my RSS feed

Note: this article has been updated on Sept 3, 2009

I am using Aweber to email out a client’s blog entries.  The client is very particular about preserving his formatting.  He wants the entry to appear the same in both the email and his blog page.

Aweber’s Blog Broadcast Messages are fed by the item:description tags in an RSS feed from the blog.

The description tag is fed by the excerpt of that blog entry.  If none is defined, WordPress grabs the first few dozen words and ends it with “…” to indicate there is more but you have to go to the blog site to read it.

This was fixed this using the Advanced Excerpt plugin. Not only does this plugin copy the contents of the blog entry in its entirety, but also copies in the HTML code.  I set it to copy the first 1000 words. The blog entries are usually very short so this length works fine.  HTML tags are not counted in the 1000 words.

The next problem came when I set up the Blog Broadcast in Aweber. Extra lines were added to the emails I received.  In the source code of the message in my email client and at Aweber.com, I looked at the code of the messages sent out.  I found an extra <br /> tag that was not in the RSS code it was pulling from.

I made a copy of one of the messages that had went out, and removed all the extra <br /> tags and sent the message as a test.  No extra spacing this time.  This told me, the problem had to occur in the RSS import process.

My guess is that there is code to replace new line characters (n) with <br /> tags for those people who who just use plain text in their excerpts to maintain their formatting.

I asked Aweber about this and they are looking into the problem after I convinced them there was a problem.  I’m still awaiting on a response.

Meanwhile, in case they can’t fix it for some reason, I think I came up with another solution.  I am using Yahoo! Pipes to search the item:description tags of my RSS feed, and strip out the new line characters using regular expressions.  Regular expressions tend to tie my brain in knots, but a little research at Brooks Brayne’s blog showed me what to do.

yahoopiperemovenewline

Above, I’m telling pipes to search the item.description for all new line characters and replace them with nothing a space. Had to put a space in there because words would wind up mashed together.

The preview window in Pipes shows exactly what I wanted to see.

However, the code in the actual RSS feed for the Yahoo! Pipe is showing the left and right angle brackets as &lt; and &gt; which could be a problem.  I was afraid the &lt; and &gt; are going to appear in the email instead of the angle brackets. But email turned out perfectly.

Except for the plain text version. Aweber strips out all the HTML tags, and with no new line characters, the text doesn’t break into separate lines.

Next I will try searching for the <br /> tags and removing them as well as the </p> (end paragraph) tags and leave the new line characters intact.  This way, Aweber can insert their <br /> tags and the plaintext will look right.

Update 09/03/2009: Aweber appears to have fixed this issue and my fix caused a problem today.  The newline characters [/n] are now appearing in the emails.  I changed RSS feed back to regular blog feed instead of going through Yahoo! Pipes.  But I definitely need to keep Pipes in mind should I run into a similar issue again.

Update 09/04/2009: OK, it wasn’t Aweber.  I looked at the code coming out of Pipes and the [n] code is visible there.  I think the code changed somewhere, but Brooke Bayne’s blog now shows that the proper code for a new line is [n].  Or maybe it always said that and I messed it up… but then why did it work before?

WordPress Pretty Permalink Tip

If you have pretty permalinks turned on in WordPress and the permalink to one of your posts is not working, check the permalink for percentage signs (%).

What happened? If you composed your entry in Word or some other word processor, that program probably has an auto-correct feature that turns straight single (or apostrophe) and double quotes into curly quotes automatically (MS Word calls them smart quotes). Then you copied and pasted your title straight from the word processor to the title field of your blog. When you published the post, WordPress tried to convert the curly quotes to something more URL friendly, but not all web browsers and/or servers recogize that format.

Solution: The best thing to do is edit the permalink (either from clicking Quick Edit on the Edit Posts page or on the full edit page for that post, click the permalink edit button directly under the title field.  Then delete any % sign you see and the 2 characters after the % sign.  The new pretty permalink should work after that.

WordPress email and Godaddy

I have WordPress installed on a Godaddy Windows hosted server.  Email is not working to retrieve passwords.  I get this error:

The e-mail could not be sent.
Possible reason: your host may have disabled the mail() function…

Fix: Installed the WP-Mail-SMTP plugin. Set up my email address in the From, and set the outgoing server to relay-hosting.secureserver.net with no authentication.

And it worked.

I am also using the CForms plugin.  Under Global settings, I had to enter relay-hosting.secureserver.net to get it to email form submissions properly.

Update: Here are the settings I am using for the WP-Mail-SMTP plugin:

From Email: (I’m using a non-Gmail email address. See why here.)

From Name: (my name)

Mailer: “Send all WordPress emails via SMTP.” is checked

SMTP Host: relay-hosting.secureserver.net

SMTP Port: (blank)

Encryption: No encryption

Authentication: No authentication

Username: (blank)

Password: (blank)

Update 2009-10-25: If you are using a virtual dedicated server at Godaddy you will need to use k2smtpout.secureserver.net instead for the SMTP host.  Thanks to @koset for finding the info here: http://help.godaddy.com/topic/91/article/150