Pippins Plugins
  • Email
  • Facebook
  • Feedburner
  • Github
  • Google
  • Twitter
  • Vimeo
  • Youtube
  • Rss
  • About
  • News
  • Join the Site
    • Member Benefits
    • Member Plugins
    • Email Notifications
  • Plugin Store
    • Affiliate Area
    • Checkout
  • Plugins
    • Plugin Portfolio
      • Plugin Portfolio – List View
    • Free
    • Premium
    • Member Plugins
    • Coding Standards
    • Get Plugin Support
  • Tutorials
    • Series
      • Plugin Development 101
      • Creating a User Follow System Plugin
      • Customizing Restrict Content Pro
      • Displaying Content with Easy Content Types
      • Writing Your First WordPress Plugins, Basic to Advanced
      • Working with Widgets
      • User Submitted Image Galleries
      • Plugin Thoughts
      • Integrating Stripe.com with WordPress
      • WordPress Rewrite API
    • Member Exclusive
      • Free Members
      • Subscriber Only
    • Difficulty
      • Beginner
      • Intermediate
      • Advanced
    • Action and Filter Hooks
    • Ajax
    • Custom Post Types
    • External APIs
    • Short Codes
    • Taxonomies
    • Video Tutorials
    • Widget Tutorials
    • WordPress Admin / Dashboard
    • Working with jQuery
    • WordPress Database
    • Writing Plugins
    • Tag Index
  • Reviews
  • Support Forum
  • Contact
    • Support the Site
    • Request Code Review
    • Plugin Support

Introduction to the gettext Filter in WordPress

Posted on June 21, 2012 by Pippin in Action and Filter Hooks, Intermediate, Tutorials, Video Tutorials 5 Comments
Home» Tutorials » Action and Filter Hooks » Introduction to the gettext Filter in WordPress
Tweet
Love It - 5

The gettext filter gives us a really easy way to change text anywhere in our WordPress install, including plugins and themes, without ever changing any of the original code. It is a great way to easily customize labels, headings, button text, and any other text we wish to change.

Like most filters in WordPress, the gettext filter is exceptionally simple to use, and the main purpose of this filter is to allow us to change text in WordPress core, WordPress plugins, and WordPress themes.

For example, let’s say a plugin has a button that says “Add to Cart”, but you would rather it say “Purchase”; the gettext filter will make changing this button label super simple. This example assumes that the plugin does not already have a method for changing the label.

A very important thing to note about the gettext filter, however, is that it only works for text strings that are localized and ready for translation.

Note, as pointed out by Otto, you should take care when using the gettext filter, as it runs on every single string in WordPress core.

Have you ever used the gettext filter before? have problems with it? Found it to be awesome, or terribly confusing? Let me and everyone else know in the comments.

Tweet Follow @pippinsplugins
add_filter, gettext, localization

5 comments on “Introduction to the gettext Filter in WordPress”

  1. Gregg FranklinGregg says:
    June 25, 2012 at 9:31 am

    Thank you!

    Reply
  2. Bruce says:
    July 18, 2012 at 8:59 am

    Great tip, especially for us semi-neophyte WP coders :)

    Thanks Pippin!

    Reply
  3. Per Soderlind says:
    August 9, 2012 at 12:25 pm

    I use the gettext filter to remove the annoying “Comments are closed.”:


    add_filter('gettext', 'ps_remove_comments_are_closed', 20, 3);

    function ps_remove_comments_are_closed($translated_text, $untranslated_text, $domain) {
    if ( $untranslated_text == 'Comments are closed.' ) {
    return '';
    }
    return $translated_text;
    }

    The plugin is available in the WP Plugin Repository: http://wordpress.org/extend/plugins/remove-comments-are-closed/

    Reply
  4. GeorgeInRaleigh says:
    March 18, 2013 at 3:59 pm

    Completely lost me. I guess I’ll just need to deal with it as is. Thanks.

    Reply
    • Pippin says:
      March 19, 2013 at 8:47 am

      If you let me know which part you’re confused by I’ll be happy to help clarify it.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Login

Lost your password?

Please enter your username or e-mail address. You will receive a new password via e-mail.

  • Facebook Become a Fan Like

  • Twitter Subscribe on Twitter Follow

  • YouTube Follow my Videos Subscribe

  • RSS Feed Subscribe with RSS Subscribe

Easy Digital Downloads

Most Loved

  • Love It Pro for WordPress
  • Write a “Love It” Plugin with Ajax to Let Users Love Their Favorite Posts / Pages
  • Simple Notices Pro Plugin for WordPress
  • User Bookmarks for WordPress
  • Front End Registration and Login Forms Plugin

Similar Plugins and Posts

  • Plugin Development 101 – An Intro to Filters
  • Let’s Talk Extensible Code
  • Playing Nice with the “the_content” Filter
  • Adding Custom Fields to the Easy Digital Downloads Checkout
  • Add Custom Links to User Row Actions

Latest Premium Content

  • Plugin Development 101 – Introduction to Adding Dashboard Menus
  • Plugin Development 101 – Intro to Loading Scripts and Styles
  • User Follow System – Part 5
  • Plugin Development 101 – Intro to Short Codes

Latest Tutorials

  • Storing Session Data in WordPress without $_SESSION (19)

    The term Session in web development refers to...

  • Test Your Plugins with RTL (1)

    Right-To-Left languages are those that...

  • Submitting Your First Pull Request to a WordPress Plugin on Github (5)

    Github is an extremely popular tool for managing WordPress plugins, and one...

Enter your email to receive automated updates when new posts are published

WP Core Contributions

  • [24316]

View the ticket on Trac.

WP Codex Contributions

  • Function: shortcode exists
  • Function: has shortcode
  • Function: shortcode exists
  • Function: shortcode exists
  • Function: has shortcode

View all 41 changes in the Codex.

Latest Tweets

  • Could not fetch Twitter RSS feed.

Topics

campaign monitor add_options_page hook get_user_meta Rémi Corson the_content meta box register_setting Sugar Event Calendar attachments wp_enqueue_script contextual help shortcodes authors Related posts attachment image forms do_action plugin mail chimp login short codes comments recent posts post types apply_filters short code bbpress taxonomies custom post type gallery images Ajax Stripe taxonomy jquery widgets users add_filter easy content types add_action widget restrict content pro easy digital downloads

Weekly Newsletter

Useful Links

  • Join the Site
  • Plugin Store
  • Affiliate Area
  • Tag Index
  • Support the Site
  • Suggest a Tutorial
  • Random Post
  • Contact

Monthly Archives

(c) 2013 Pippin's Plugins