My Favorite Social Network: Google+

I unintentionally took last week off from posting. I guess I git a little caught up in my various projects that it slipped my mind. I hope to get back on track this week but before I do I thought I would direct your attention to a guest post I wrote for http://area2oh3.com/. They’ve started a series this week called, “My Favorite Social Network” and I offered my two cents on Google+. Check it out at the link below and be sure to leave a comment there is you can.

My Favorite Social Network: Google+

Easily add text to post title based on category

Have you ever wanted to add a little specification to your post titles if they were in a certain category. For instance this post. I have it filed under “Quick Tip”. What if I wanted to add the text “Quick Tip:” in front of every post in that category. It’s pretty simple.


add_filter( 'the_title', 'my_modify_title', 10, 2 );
function my_modify_title( $title, $id ) {
   if( in_category( 'Quick Tip', $id ) ) {
      $title = '<span class="quick-tip">Quick Tip:</span> ' . $title;
   }
   return $title;
}

Add this code to your site functionality plugin and change it for your particular category and you are all set. I even wrapped the added text in a span in case you wanted to style it to make it stand out.

One thing to keep in mind. You can do an if/else in here to do this for several categories if you like but it certainly works best if you are assigning one category per post. Otherwise it will simply use the first match.

How to modify the main WordPress query the right way

Have you ever wanted to tweak what content WordPress served up on a particular portion of your website? Perhaps on your home page instead of the default 10 posts you only want to show 3 or maybe you want to exclude a particular category.

When I started in WordPress, and still even now, the way most people do it is by editing the WordPress loop in your themes template files. It’s usually done by adding a call to the query_posts function and a few arguments right before the while portion of the loop. There are a couple problems with this method though.

  1. It doesn’t support pagination
  2. You have to edit every template file where you want to modify the query

This makes this method a poor choice. Lot’s of themes and plugins use pagination and it’s great way to navigate your posts. Why break it? Also, anytime you upgrade your theme you will overwrite your changes. You could just copy those templates into a child theme but if you are going to copy all the structure over to a child theme, it’s not really a child theme anymore.

So what if I told you there was a much easier and cleaner way of doing this?

Continue reading

Google Drive – Almost there

This is not like our usual posts. It’s not about one of our products or even WordPress at all. It is, however, about a tool that I have been excited about for a long time and it’s finally launched. In fact it just launched yesterday.

Google Drive is Here!

If you haven’t heard about this service yet it’s basically Dropbox by Google. Now that may not mean anything to you but I generally love Google’s products and how they all integrate with each other. Google helps me streamline my workflow and keep everything available regardless of where I am and that’s a huge win for me. This is just the next step in that evolution.

  • Gmail – Keeps all of my communication in one place and yet accessible everywhere.
  • Google Docs – Lets me collaborate with anyone I want on documents and spreadsheets for any of my devices.
  • Google Reader – Delivers all of the news that’s most important to me regardless of where I am at the moment.
  • Google+ – Keeps me connected to many friends, colleagues, acquaintances, and customers at a moments notice.

Now Google Drive can handle everything else. All my web projects, graphic files, and other miscellaneous files that I might need at any given moment.

Google Drive was just released yesterday so there are bound to be some glitches and less than stellar features but I’m confident in Google’s ability to listen to the public and push out frequent improvements. If they are even half as responsive as they have been for Google+ we will be seeing a lot of great stuff fairly regularly.

One Google Drive Warnings!

I’ve been playing with the service since yesterday and there are a few things you should be mindful of.

  • Google Drive is not yet a back-up solution. By that I mean, if you delete a file in your local Google Drive folder, it’s deleted online as well and thus on every device you sync with. I’m hoping that come up with a solution for that but that’s how it stands now.

Why Use Google Drive?

Why not? You get 5gbs of storage for free and the cost of additional storage is dirt cheap. In all seriousness here are a couple reasons why I’m using Google Drive.

  • I want all my web development files and certain applications accessible everywhere. I work on several different devices and it’s a pain to have to carry around an external drive everywhere I go. Plus, I can’t plug my external drive into my iPhone or iPad.
  • Back-ups! I know I said that Google Drive isn’t yet a back-up solution and that’s true if you delete an entire file or folder. It’s a great solution if you accidently made a change you didn’t mean to. Go online and just download a previous version of that file and all is well. That’s a nice little safety net.

I may come up with a few more as I dig into the service a little more and as they mature the service moving forward but all in all I’m very pleased and looking forward to where the project is headed.

PSA: How to Add… Without a WordPress Plugin

Let me be extremely clear. If you ever read an article that includes the phrase “how to add anything with out a plugin”, beware! They do not necessarily have your best interests in mind. What they generally have in mind is getting traffic by giving you what you want.

Don’t get me wrong, not everything you want to do absolutely has to be in a plugin, but more times than not it should be. So why do we see all these articles popping up about how to do all this stuff without a plugin? Mostly because you keep looking for it. People who post these tutorials want traffic so they are going to give you what you want. But is that how we make the community better, by giving people only what they want but never what they need?

The real question isn’t why are people writing tutorials like these, that’s easy. The question is, why are you searching to do things the wrong way. I know that sounds harsh but it’s the truth. When you try to avoid using a plugin 9 times out of 10 you are doing it wrong because a plugin is exactly what you need. It’s my job to try and educate you to make better choices. So here are 3 myths you believe that are keeping you away from doing it the right way.

Continue reading

How to Translate a WordPress Plugin

We get quite a few emails asking how to translate our plugins so I thought it might be a good time to layout the process just a bit. The process is actually pretty simple but if you’ve never done it before and be a little intimidating.

The entire process is done in two steps.

  • Internationalization: This is the process of making the plugin or theme ready for translation by marking specific strings of text. This is handled by the developer.
  • Localization: This is the process of translating the strings and making WordPress serve the appropriate files. This is handled by anyone who wants the plugin in their own language.

What you will need

  1. A plugin (or even a theme) that has been properly internationalized. Both Ninja Forms and Ninja Announcements are translation ready.
  2. A gettext file editor like poedit. This is program that you will use to create your translation files

The files you will be using

There are 3 types of files used when translating a plugin, theme or even WordPress itself.

  • .mo which stands for Machine Object. This is the file you will be creating for your custom translations.
  • .po which stands for Portable Object. This is the file you will translate.
  • .pot stands for Portable Object Template. This is the file by which the .po is created and is essentially the same as .po.

If your theme or plugin has been Internationalized you should find a folder named “lang”, “language, or similar. You will find at least some of the above mentioned files in there. Let’s get started.

Translating

1. Run Poedit and select File > New catelog from POT file

You will then to proceed to enter some details about yourself and then be prompted to save your work thus far.

There is a specific naming convention for these files in in order for WordPress to be able to serve them properly. It’s based on the language code (e.g. pt for Portuguese) followed by the country code (e.g. _SE for Sweden). For Swedish the file would be called sv_SE.po. See the complete list of language codes and country codes to find your exact locale.

For plugins it’s there is one more thing…the plugin name. So for our plugin Ninja Announcements the file would be named ninja-announcements-sv_SE.po.

2. Translate each the text

Poedit has three sections:

  1. The first section is a listing of all the the text available for translation. Click on a line to translate it.
  2. Beneath that it will display the current text you are viewing. This is just for reference.
  3. Finally, beneath that is the section where you will type your translation.

So all you have to do is click on a line. Translate the text and then move in to the next line until all the text has been translated. A star will appear in the first section to the left of each line that you have translated along with your translation to the right.

Be careful when typing in special characters. these sometimes need to be converted to what’s called “html entities”. Things like apostrophes, single quotes, ampersands, etc. check out http://www.w3schools.com/tags/ref_entities.asp for a listing of these entities to look out for.

Once you are done click “Save Catalog” button and your new files will be updated. You should be able to upload and test them out immediately.

Is your WordPress install ready for translations?

All this is great but if you install hasn’t been set up to serve the translated files it won’t make much of a difference.

To accomplish this you will need to change to your WordPress wp-config.php file with the correct language codes. Here is more info about getting WordPress in your language.

define ('WPLANG', 'sv_SE');

I hope you found this helpful and if you do translate any of our products please send us the file and your name and website. We would love to add you to the readme.txt of language contributors.

Extending and Depending On Other Plugins

I’ve been sharing a lot lately about adding menu items and widgets to your dashboard. In many of these cases I’m tapping into specific functions from other plugins. So what happens to my website if I stop using that plugin or deactivate it for some reason? It crashes or throws all kinds of ugly errors, that’s what happens. And neither you or your visitors want to see that. But don’t fret, there is a real simple way to “crash-proof” your website in these instances.


if ( function_exists( 'SOME FUNCTION NAME' ) ) { YOUR CODE HERE }

You should always use this check if including a function into your theme or plugin from another plugin. What is does is check to see if the function you are mentioning is a registered function. If it is, the script will continue to run as normal. If not, the script will not proceed. That way if you deactivate to remove the plugin altogether your site will continue to run fine, it will just exclude that particular functionality.

The function_exists call can be used in a variety of instances but sometimes you want to build a dependency upon another plugin completely. For instance, as long as another plugin is active, here is a bunch of things that I want to do to extend it further. WordPress has the perfect solution for these instances.


if ( is_plugin_active( 'ninja-newsletters/ninja-newsletters.php' ) ) { YOUR CODE HERE }

In my example above I had a bunch of stuff I wanted to do if my Ninja Newsletters plugin was active. All it needs is the name of the main plugin file. In my case the file is in a directory named “ninja-newsletters” and the files is “ninja-newletters.php” so my complete check is “ninja-newsletters/ninja-newsletters.php”. Pretty easy.

Which One Should I Use

The answer is, it depends. It comes down to performance and testing.

function_exists will basically look through every function that is defined within your site until it finds the one you told it to check for. On my site I currently have 6090 defined functions. If you end up doing this a lot on a single page, I’ve not tested this, I could see it starting to slow down the site a bit.

is_plugin_active technically is meant only for your WordPress admin. You can use it on the front end but you would need to include plugin.php before calling the function. The advantage that I see in using this method is that the script doesn’t have to look through a long list of functions like a needle in a haystack to see if a particular function is defined. You tell it exactly what should be active and where it is. The script doesn’t have to find anything.

Of course all of this can depend on other variables so choose what you think is the best option for you and always test your work and see how it’s working efficiently enough for you.

Add a Custom Widget to your WordPress Dashboard

Yesterday I shared how to add some content to the “Right Now” WordPress dashboard widget. On occasion though you may have content that you would like to display on your dashboard that doesn’t quite fit into the “Right Now” widget. In that case you might want to create a custom dashboard widget. Here is all it takes.

Just copy and paste the code below to your site functionality plugin or create a new plugin.


// Function that output's the contents of the dashboard widget
function my_dashboard_widget_function() {

  // Enter your code here.

}

// Function that called by the action hook below to register the dashboard widget
function my_add_dashboard_widgets() {

  wp_add_dashboard_widget('dashboard_widget', 'WP Ninjas Sales Stats', 'my_dashboard_widget_function');

}

// Register the new dashboard widget into the 'wp_dashboard_setup' action
add_action('wp_dashboard_setup', 'my_add_dashboard_widgets' );

Pretty simple, right? Now I didn’t place any code in our dashboard widget because the possibilities are endless. My recent use case was to get all the sales from our transactions table and display them as a total and as individual products. This gives me a quick at-a-glance look at our sales and which products are doing the best.

What might you want to display in your WordPress Dashboard?

Add Information to the “Right Now” Dashboard Widget

The “Right Now” WordPress Dashboard widget is a familiar sight on any WordPress install. It displays helpful information as to how many posts, pages, links, categories, and tags you currently have as well as info about the number of comments and widgets. It also tells you the current theme and WordPress version you are running on. All helpful information.

After your site has been around a while you may have added some custom post types, taxonomies or other info you might want to have available as well. This is really easy to do and I’ll show you how by adding  a custom post type to my “Right Now” Dashboard widget.

Continue reading

Ninja Forms 2.0 – Coming Soon!

This is an extremely important post and you will want to take it all in. Especially if you have not already purchased a subscription to Ninja Forms.

Near the end of May we will be releasing Ninja Forms 2.0. This is a huge release with a ton of new features (see below) and with it will most likely come with some changes to our subscription process. We might be moving to an annual subscription for continued updates and support as well as raising prices. The full details of this change are still being fleshed out, but changes will be made. Why is this important?

Anyone who purchases Ninja Forms before these changes are made will be grandfathered into our current subscription rate for life. That means you will still continue to get unlimited updates and support with absolutely no need to renew your subscription annually. That’s right, one $30.00 purchase and you get everything Ninja Forms is and will become, while never have to pay another dime. At our current price, this will save you $30.00 a year but at our yet undetermined prices who knows how much you will save.

All that to say that buy now to get the best features at the lowest possible cost.

Now onto what we are adding to Ninja Forms version 2.0

Continue reading