Use get_the_title(), not $post->post_title

WordPress lesson of the day:

If you want the title of a WordPress post, use the function get_the_title($post->ID) and not $post->post_title.

Both should work, but I found when you use smart or curly quotes (both single and double) in your post titles, using $post->post_title returns an empty string. Perhaps running a filter function would help, but I have no reason to go through that trouble right now.

 

 

 

$_SESSION variables in WordPress

Using $_SESSION variables in WordPress?  You need to add this line to your wp-config.php file:

if (!session_id()) session_start();

Posted in PHP

WordPress 3’s New Menus

WordPress 3 has brought forth some new tricks like the customizable navigation menus which make it very easy to set up your own menus using a GUI. You can define and drag-and-drop the order of the menu items, and WordPress will output them as an unordered list (<ul><li>…</li></ul>).

Rather than try to explain it myself, just head over to Justin Tadlock’s post about the menus.

One missing piece was filled by John The Developer where I needed to add a custom class to the last menu item.  I was displaying a menu horizontally and using “margin-right” to space the menu items (inside <li> tags) apart, but I didn’t want that margin on the last item.  Here is John’s 8 lines of code solution.

Then in my CSS file, I defined “last-item” class as:

li.last-item {
     margin-right: 0 !important;
}

I did try using the pseudo-class of li:last-child which worked fine in Chrome and Firefox, but it did not work for Internet Explorer because IE has yet to recognize pseudo-classes.

Update Bonus: Want to add some collapsing menu goodness? Check out Daneomatic.com’s post.

FeedWordPress making invalid RSS?

As I mentioned in my last post, I’m using FeedWordpress to syndicate affiliate links.  I turned on the option to have the permalink to the affiliated articles to go straight to the affiliate link instead of the page (that may be bad for SEO, but one less click for visitors).

The problem was the RSS feed became invalid because of the affiliate link.  So I need to encode the link.  So on line 590 of feedwordpress.php, I changed

$uri = get_syndication_permalink();

to

$uri = esc_attr(get_syndication_permalink());

The esc_attr function is a built in WordPress function that converts certain characters to their HTML encoded equivalents. Such as “&” becomes “&amp;”.

Everything seems to be working fine now.

LinkShare AdMix and SEO Friendly Images plugins

If you are a LinkShare affiliate, there a great plugin called LinkShare AdMix that uses the RSS feeds of retailers you have partnered with to automatically insert posts of each item in the feed.  I had to do 2 things to get it to work:

  1. Line 111 of feedwordpress.php, I had to change $fwp_path = ‘feedwordpress’; to $fwp_path = ‘linkshare-admix’; because the code was not finding the install folder correctly.  Changing the folder name from “linkshare-admix” to “feedwordpress” may have worked too, but there is already a FeedWordpress plugin (which this plugin is based on) out there and should you need to install both for some reason, you don’t need them butting heads*.
  2. Be sure you copy the included Magpie RSS  files into your wp-includes folder to get everything to work right.

I noticed that the images the Linkshare feed was posting were not SEO’d – no alt or title tags.

Enter the SEO Friendly Images plugin which adds alt and title tags for you based on the posts title and keywords.  But it didn’t work.

Usually plugin problem lie in an incompatibility with another plugin, so I disabled a plugin one at a time to determine which one was causing the problem.

Guess what?  It was the LinkShare AdMix plugin.

I wondered if the original FeedWordpress plugin had the same problem, so I disabled the LinkShare AdMix plugin and installed the FeedWordpress plugin.  Same problem.  I remember seeing filters were called in the source code, so I searched for “filter” and found a commented paragraph about preserving the feed and not allowing other plugins to change it.  The 2 offending lines of code followed, and I promptly commented them out:

//add_filter(‘the_content’, ‘feedwordpress_preserve_syndicated_content’, -10000);
//add_filter(‘the_content’, ‘feedwordpress_restore_syndicated_content’, 10000);
Update: Yes, I totally missed the built-in option to “Expose sydicated posts to formatting filters” under Syndication options > Post & Links > Formatting >Formatting filters. *facepalm*  But this only works for the FeedWordpress plugin.  LinkShare AdMix plugin does not have this option, so you will need to comment out the 2 lines of code above to get it work with the SEO Friendly Images plugin.
Commenting out that code worked.  Just remember you will need to do this again when the Linkshare Admix plugin gets updated.
In the end, I think I will stick with FeedWordpress instead of LinkShare AdMix because I get more fine tune control and easier to add RSS feeds.
*I think installing both LinkShare AdMix and FeedWordpress would not workout because then need different versions of Magpie RSS.  Some recoding would be required to get them to play nice.