Powerful WordPress Tips And Tricks

Advertisement

I’ve been working with WordPress since the dawn of time, and even though I peek at the source code regularly, I still discover new tips and tricks. I’ve compiled my own list of 21 techniques that are handy, clever, fun or best practices rarely followed. I hope everyone finds something new in the list!

21 tips1

1. WordPress Has A Ton Of Built-In Scripts

Using the great wp_enqueue_script() and wp_enqueue_style(), you can include styles and scripts easily with dependency management. But did you know that WordPress has a lot of scripts already built in? jQuery, many elements of jQuery UI, jQuery Form, SWF Object, Tiny MCE, Jcrop and Thickbox are just some the better known ones. The whole list can be found in the WordPress Codex2. If you’re interested in learning how to use the enqueue functions effectively, I recommend “The Developer’s Guide to Conflict-Free JavaScript and CSS in WordPress3” right here on Smashing Magazine!

2. Replace Built-In Scripts By Deregistering Them

If you live on the bleeding edge, you can use versions of scripts other than the built-in ones. Using a newer jQuery version is common (though not necessarily good) practice, which can be done in the following way.

function my_scripts_method() {
   wp_deregister_script( 'jquery' );
   wp_register_script( 'jquery', get_template_directory_uri() . '/js/jquery-new.js');
   wp_enqueue_script( 'jquery' );
}
add_action('wp_enqueue_scripts', 'my_scripts_method');

But do not do this just to brag about using latest stuff. WordPress includes the version of jQuery that it does to ensure maximum compatibility.

Use another version of jQuery only when encountering compatibility issues, such a plugin that specifically requires it.

3. Force Perfect JPG Images

This is a classic example of why working on a team is beneficial. My good friend Lars told me that WordPress doesn’t use 100% quality for images served on the website, to conserve space and bandwidth. He also showed me a solution, of course:

add_filter( 'jpeg_quality', 'smashing_jpeg_quality' );
function smashing_jpeg_quality() {
   return 100;
}

WordPress uses a default quality of 90%. This is fine in most cases; I doubt many people can see the difference. But if top-notch image quality is a must on your website (for a portfolio, photography, etc.), modifying the value might be best.

4. FeedBurner Redirection

FeedBurner is used on almost every blog that I’ve worked on, and yet I never know how exactly to set it up by heart. Thanks to Elio for writing “10 Tips to Optimize Your WordPress Theme4,” which contains this snippet:

add_action( 'template_redirect' , 'smashing_rss_redirect');
function smashing_rss_redirect() {
   if ( is_feed() AND !preg_match( '/feedburner|feedvalidator/i', $_SERVER['HTTP_USER_AGENT'] ) ){
      header( 'Location: http://feeds.feedburner.com/my_smashing_feed' );
      header( 'HTTP/1.1 302 Temporary Redirect' );
   }
}

5. Using General Taxonomy Functions

A number of taxonomy functions can handle your custom taxonomies as well as the built-in tags and categories. The Codex’s reference of functions5 contains the full list of taxonomy functions. I particularly like using get_term(), get_terms() and wp_get_object_terms(). To make things more modular, I use these functions as much as I can, even for tags and categories.

6. Setting Up Sessions In WordPress

Sessions are great for storing information between pages and are widely used on websites. WordPress doesn’t use them at all internally, so the session is never set. Using the following method, you can start a session on all pages before any output.

add_action( 'init', 'smashing_session_start' );
function smashing_session_start() {
   if ( !session_id() ) {
      session_start();
   }
}

Note that, while sessions are generally pretty safe, implement IP checking or added nonce protection just to be on the safe side. As long as you’re transmitting non-sensitive data, though, you’ll fine. Check out Mark Jaquith’s great article on nonces6 for more info.

7. List All Hooked Functions

I started writing a function to do this. When I did a quick Google search, it turned out that WP Recipes had exactly7 what I needed.

function list_hooked_functions($tag=false){
   global $wp_filter;
   if ($tag) {
      $hook[$tag]=$wp_filter[$tag];
      if (!is_array($hook[$tag])) {
         trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
         return;
      }
   }
   else {
      $hook=$wp_filter;
      ksort($hook);
   }
   
   echo '<pre>';
   
   foreach($hook as $tag => $priority){
      echo "<br />&gt;&gt;&gt;&gt;&gt;t<strong>$tag</strong><br />";
      ksort($priority);
      foreach($priority as $priority => $function){
         echo $priority;
         foreach($function as $name => $properties) {
            echo "t$name<br />";
         }
      }
   }
   echo '</pre>';
   return;
}

Used without an argument, you’ll get a nice list of all hooked functions. This will be a bit long, so you can specify a hook to narrow the list a bit. This is particularly useful when debugging or fiddling around with hook priorities. Knowing what’s hooked into wp_head() in what order is important, and this function is a great asset!

8. Automatically Add Paragraph Tags To Anything

WordPress does this automatically to the content and the excerpt, but there’s no reason not to use it elsewhere. The function responsible for turning double line breaks into paragraphs is wpautop()8.

$my_text = 'Welcome!
Smashing Magazine is a great place to learn new things.
I hope you’re having a nice time!';

echo wpautop( $my_text );

Sometimes you’ll want to disable this filter by default, which you can do by removing it from the content and excerpt, like so:

remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );

9. Send Emails Using WordPress

A little while back, I wrote a long article on “Creating Perfect Emails for Your WordPress Website9,” a part of which has to do with using the wp_mail() functions. These functions let you use built-in WordPress awesomeness to send emails to users.

$message = 'Hello, thanks for reading my post! I hope to see you back soon.';
wp_mail( 'someonesemail@example.com', 'Thanks for reading my post!', $message);

You can also send HTML content by using a filter:

add_filter ("wp_mail_content_type", "smashing_mail_content_type");
function smashing_mail_content_type() {
   return "text/html";
}

10. Native Pagination Links

It came as a surprise to me about six months ago that you don’t need any plugins to pull off proper paging (i.e. not just “Previous” and “Next” links); you can do it with a native function. The paginate_links() function is a handy little thing that lets you show pagination for any type of content, not just a WordPress loop.

// Pagination for a WordPress loop
$list = new WP_Query( $query_args );
$pagination = array(
   'base'       => str_replace( 99999, '%#%', get_pagenum_link( 99999 ) ),
   'format'     => '?paged=%#%',
   'current'    => max( 1, get_query_var( 'paged' ) ),
   'total'      => $list->max_num_pages,
   'next_text'  => 'next',
   'prev_text'  => 'previous'
);
echo '<div class="pagination primary-links">' . paginate_links( $pagination ) . '</div>';

// Pagination for anything
$list = range(1, 100);
$items_per_page = 12;
$pagination = array(
   'base'       => get_bloginfo( 'url' ) . '/mypage/%_%',
   'format'     => '?paged=%#%',
   'current'    => $_GET['current_page'],
   'total'      => ceil( max($list) / $items_per_page ),
   'next_text'  => 'go forth',
   'prev_text'  => 'go back'
);
echo '<div class="pagination primary-links">' . paginate_links( $pagination ) . '</div>';

11. Upload Files With Ease

WordPress has a bunch of great uploading functions for everything from checking the file type to finding the uploads directory. A more obscure function is wp_upload_bits()10, which you can use to upload a file to the uploads directory.

$upload = wp_upload_bits( $_FILES['myfile']['name'], null, file_get_contents( $_FILES['myfile']['tmp_name'] ) );
echo 'Well uploaded! The path to this file is ' . $upload['file'] . ' and the url to this file is ' . $upload['url'];

12. Twitter-Like Time Display

This was another shock to me a while back, especially since it has been in WordPress since version 1.5! If you’d like to show viewers a relative date in a human-readable format, like “5 minutes ago” or “one month ago,” try the human_timed_diff()11 function.

$diff = human_time_diff( '2012-05-05 12:05:00', '2012-05-05 12:10:00' );
echo 'This comment was submitted ' . $diff . 'ago';

// Output: This comment was submitted 5 minutes ago

13. Log In As Any User

If you’re building a complex website with many roles, being able to switch between them quickly and easily would be useful. The wp_set_auth_cookie()12 lets you log the current user in based on ID.

$user_id = 4;
   wp_set_auth_cookie( $user_id );

Take great care when using this function; left unchecked, it could log every user in as user number 4. Even while testing, I target it specifically to my IP, and maybe even to a special URL string just to be sure. That said, with proper safety, it can be used as part of a custom log-in script.

14. Add Custom Profile Fields In The Admin Area

I can’t say that WordPress offers much in the way of profile customization in the administration area. Especially nowadays, when you want to show the Twitter and other social accounts of authors, this is a shortcoming. It can be fixed easily, though. Have a look here:

<?php
add_action( 'show_user_profile', 'smashing_profile_fields' );
add_action( 'edit_user_profile', 'smashing_profile_fields' );

function smashing_profile_fields( $user ) { 
?>

   <h3>Social Sites</h3>

   <table class="form-table">

      <tr>
         <th><label for="twitter">Twitter</label></th>

         <td>
            <input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" /><br />
            <span class="description">Your Twitter Username</span>
         </td>
      </tr>

      <tr>
         <th><label for="twitter">Facebook</label></th>

         <td>
            <input type="text" name="facebook" id="facebook" value="<?php echo esc_attr( get_the_author_meta( 'facebook', $user->ID ) ); ?>" /><br />
            <span class="description">Your Facebook Profile URL</span>
         </td>
      </tr>
      
      <tr>
         <th><label for="twitter">Linkedin</label></th>

         <td>
            <input type="text" name="linkedin" id="linkedin" value="<?php echo esc_attr( get_the_author_meta( 'linkedin', $user->ID ) ); ?>" /><br />
            <span class="description">Your Linkedin Profile URL</span>
         </td>
      </tr>

   </table>

<?php
}
add_action( 'personal_options_update', 'smashing_save_profile_fields' );
add_action( 'edit_user_profile_update', 'smashing_save_profile_fields' );

function smashing_save_profile_fields( $user_id ) {
   if ( !current_user_can( 'edit_user', $user_id ) )
      return false;

   update_user_meta( $user_id, 'twitter', $_POST['twitter'] );
   update_user_meta( $user_id, 'facebook', $_POST['facebook'] );
   update_user_meta( $user_id, 'linkedin', $_POST['linkedin'] );
}

15. Sanitize URLs With Ease

When working with URLs, always make sure they are properly formed and don’t contain any invalid or dangerous characters. The esc_url()13 function lets you do just that.

$my_url = 'http://mypage.com/?awesome=true';
   $url = esc_url( $my_url );

Be sure to check out all of the other escape functions. You can find a list of them at the bottom of the page that I linked to in the related section.

16. Empower Text Widgets

To make text widgets so much better, you can enable the use of shortcodes in them. This is a great tool for theme developers because it makes your product much more flexible for the user.

add_filter( 'widget_text', 'do_shortcode' );

17. Add Custom Post Types To The RSS Feed

Not being able to do this easily from the admin area is a big issue. Many website owners separate their content into custom posts, and they also want all of their items to show up in the feeds. Never fear — a function is here!

add_filter('request', 'smashing_custom_feed');
function smashing_custom_feed( $vars ) {
   if ( isset( $vars['feed'] ) ) {
      $vars['post_type'] = get_post_types();
   }
   return $vars;
}

While this is great, it forces all of your post types into the feed. If you’d like to add just some of your custom post types to the feed, you can list them separately.

add_filter('request', 'smashing_custom_feed');

$post_type_list = array( 'post', 'products' );
function smashing_custom_feed( $vars ) {
   if ( isset( $vars['feed'] ) AND !isset( $vars['post_type'] ) ) {
      $vars['post_type'] = $post_type_list;
   }
   return $vars;
}

18. Don’t Break WordPress Loops

Multiple loops are great but can wreak havoc if not used correctly. To make sure your loop runs smoothly and you can still use all of the functions that rely on globals, store the original query in a temporary variable.

$tmp_query = $wp_query;
query_posts('cat=5&order=ASC');
while( have_posts() ) : the_post() 
?>
   <a href="<?php the_permalink() ?>'><?php the_title() ?></a><br />
<?php
$wp_query = $tmp_query;

19. Custom Database Queries

If you need something more than what the default WordPress functions give you, you can use $wpdb14, the WordPress database class to query the database directly.

$recent_users = $wpdb->get_results( "SELECT display_name, user_registered FROM $wpdb->users ORDER BY user_registered DESC LIMIT 0,10" );

This class has great features and functions. Take a look at “Interacting With the WordPress Database15” for an in-depth tutorial.

20. Customize WordPress Post Revisions

The post revisions feature in WordPress is great, but the majority of users don’t use it. Database entries are created for revisions, even if they are not used. While they’re not a huge hit on your server’s performance, if you don’t use revisions, you can disable them by placing the following code in your wp-config.php file.

// To remove revisions
define( 'WP_POST_REVISIONS', FALSE );

// To limit them
define( 'WP_POST_REVISIONS', 5 );

20. Styling Author Comments

If you’d like author comments to jump out, simply use the bypostauthor class in your CSS.

li.bypostauthor {
   background:#fafafa;
   color:#555;
}

21. Storing Your Whole Page In A Variable

In some cases, storing your whole output in a variable can be very helpful. This allows you to make global changes, compress or obfuscate code and more very easily. All we need is PHP output buffering and two hooks.

add_action('wp_head', 'smashing_buffer_start');
add_action('wp_footer', 'smashing_buffer_end');

function smashing_buffer_start() {
   ob_start( 'smashing_callback' );
}

function buffer_end() {
   ob_end_flush();
}

function smashing_callback( $content ) {
   // Feel free to do things to the content here
   $content = str_replace( 'great', 'awesome', $content );
   echo $content;
}

And The List Goes On

Do you have any favorite WordPress tips and tricks or best practices that you wish were followed more? Please do share in the comments so that we can all learn something new!

(al) (ea)

Footnotes

  1. 1 http://www.smashingmagazine.com/wp-content/uploads/2013/06/21tips_mini.jpg
  2. 2 http://codex.wordpress.org/Function_Reference/wp_enqueue_script#Default_scripts_included_with_WordPress
  3. 3 http://www.smashingmagazine.com/2011/10/12/developers-guide-conflict-free-javascript-css-wordpress/
  4. 4 http://www.smashingmagazine.com/2011/12/07/10-tips-optimize-wordpress-theme/
  5. 5 http://codex.wordpress.org/Function_Reference#Category.2C_Tag_and_Taxonomy_Functions
  6. 6 http://markjaquith.wordpress.com/2006/06/02/wordpress-203-nonces/
  7. 7 http://www.wprecipes.com/list-all-hooked-wordpress-functions
  8. 8 http://codex.wordpress.org/Function_Reference/wpautop
  9. 9 http://www.smashingmagazine.com/2011/10/25/create-perfect-emails-wordpress-website/
  10. 10 http://codex.wordpress.org/Function_Reference/wp_upload_bits
  11. 11 http://codex.wordpress.org/Function_Reference/human_time_diff
  12. 12 http://codex.wordpress.org/Function_Reference/wp_set_auth_cookie
  13. 13 http://codex.wordpress.org/Function_Reference/esc_url
  14. 14 http://codex.wordpress.org/Class_Reference/wpdb
  15. 15 http://www.smashingmagazine.com/2011/09/21/interacting-with-the-wordpress-database/

↑ Back to topShare on Twitter

Daniel is not only a web developer who is in love with WordPress, but also the Editor of the Smashing WordPress section. He owns a company called Bonsai Shed where they make web apps and premium themes like Musico and Estatement.

Advertising
  1. 1

    Good tips an tricks, but the paragraph ’18. Don’t Break WordPress Loops’, the right way is to use the ‘wp_reset_query’ function :)

    0
    • 2

      I don’t want to be pedantic, but according to Coredev Andrew Nacin, using query_posts is evil ;)
      One should always use WP_Query. Heres a link to a talk he gave called “You don’t know query”:
      http://wordpress.tv/2013/03/15/andrew-nacin-wp_query-wordpress-in-depth/

      That is to say, that i really liked the article! Some good advise/tips/tricks… Thanks!

      0
      • 3

        I absolutely agree with you, I hate query posts as it just makes no sense when WP_Query is there. However, for a lot of beginners query_posts is much easier and unless you have a sizable website it really won’t make a difference performance wise I think :)

        Thanks for the kind words and the correction, I should have mentioned this in the article itself :)

        0
        • 4

          You should never teach something because it’s easier to use when you know it’s wrong. This example should use WP_Query() and ending with wp_reset_postdata() as mentioned on http://codex.wordpress.org/Class_Reference/WP_Query.

          0
          • 5

            Marko… And yet we teach Newtonian physics, even though strictly speaking “it’s wrong”. Teaching something even tho it may not be entirely correct should not be ruled out. If by teaching it “right” you drive novices away to less reliable sources you are doing more harm than good. I would argue the best approach in this instance is to teach it “wrong” but to explain that there is a better, but more difficult, way to do things. This will result in the retention of readers, and when they are successful implementing the “wrong” but easier approach, will also raise their confidence in this site and themselves, thus making them more likely to come back to learn about the better approach that you advocate. This will eventually lead to more people doing things the better way – good news for everyone surely?

            0
        • 6

          I agree; query_posts as a viable solution for creating a query is bad practice and should not be encouraged.

          0
      • 7

        But don’t forget about get_posts which is very useful for newbies but is also (I found personally) a lot faster, especially for large sites. I might however be wrong :D

        0
    • 8

      And don’t use query_posts. Never. It’s evil. Just use pre_get_posts.

      More info about that, in Nacin’s talk: http://wordpress.tv/2012/06/15/andrew-nacin-wp_query/

      0
      • 9

        It all depends on who is using it and what you’re using it for. I agree that pre_get_posts is the best solution if you know what you’re doing. There isn’t much difference between query_posts and WP_Query if you’re using it for the same thing since they make the original query redundant either way.

        pre_get_posts() is the way to go but its use is for more advanced users. query_posts is not evil because it does pave the way for beginners to understanding how queries work. For more advanced users it is a definite no-no, but everything has its place.

        0
  2. 10

    As I said in my other comment: Many thanks for the article! And I know this is not a forum or a place to demand anything, but maybe someone has some info an a topic regarding WordPress:

    How does one create a loop that ALLOWS duplicates? My research so far leaves me still in the dark on this topic.

    Feel free to delete this comment if you think its way out of scope!

    0
    • 11

      Hi Ulrich,

      What do you mean by duplicates? I’ll be happy to give you some help with this if you let me know what you mean :)

      Daniel

      0
      • 12

        Hi Daniel,
        with duplicates i mean, duplicate posts/IDs in the loop. Lets say i have a query like this:

        add_filter( ‘posts_orderby’, ‘my_posts_orderby_date’, 10, 2 );
        function my_posts_orderby_date( $orderby, $query ) {
        global $wpdb;
        return ” CAST( $wpdb->postmeta.meta_value AS DATE ) ” . $query->get( ‘order’ );
        }

        $args = array(
        ‘post_type’ => ‘event’,
        ‘meta_query’ => array(
        ‘relation’ => ‘OR’,
        array(
        ‘key’ => ‘_date0′,
        ),
        array(
        ‘key’ => ‘_date1′,
        )
        ),
        ‘order’ => ‘ASC’,
        );
        $my_query = new WP_Query( $args );

        In my case, WordPress always removes duplicate IDs from the loop, so that no post is shown multiple times in the loop.
        I’m at a los here and have to admit that my knowledge of PHP/wordPress is limited (as you may see in my code example anyways ;)

        0
        • 13

          Ah, I meant more like why you would want posts to be in the loop twice so I can figure out what the best solution would be :)

          0
          • 14

            Oh sorry ;)
            the reason for this is rather simple:

            Lets say i have serveral metaboxes (dates) for a post, now i want a loop that lists the posts sorted by the metaboxes. If a post has several dates added, it should also appear several times in the loop.
            That way, you don’t need to add several posts with the same content just to have it appear multiple times in a loop.

            0
          • 15

            Get the posts by the metabox, not the id. Now you don’t have conflict.

            0
          • 16

            As Nathan says, the best way to go about this would probably be to get the post IDs from the meta boxes and loop through the results.

            0
  3. 17

    Regarding #3, this is fine if you’re only using the image at its uploaded size. Then you can upload an optimised image with jpeg_quality set to 100%. However, if you let WordPress create a bunch of images with different dimensions from this uploaded image (for example, if you’re using them for different breakpoints in responsive design), then you’ll find that a quality of 100% produces images with very large file sizes, because the resized images will not be optimised themselves.

    You can actually get the situation where an image of smaller dimensions can have twice the files size of the original, which is massively counterproductive for responsive design.

    You’ll need to play around with settings for your own images, but I’ve found 85% is a pretty good compromise.

    0
    • 18

      Christopher Ruggia

      September 26, 2013 6:47 am

      I have often wondered about image compression in WordPress. Image files add tremendously to page bloat, and proper image optimization is often touted as the first priority for increased page speed.

      With this being the case, it is surprising that WordPress doesn’t have more robust native controls for managing image optimization. In fact, it seems that if we do go to the effort to optimize our images using a decent utility for the purpose, WordPress will undermine that effort on upload by chunking out a bunch of barely compressed copies at the different specified image sizes.

      It would seem to just make that problem worse by telling WordPress not to compress our images at all with a 100% quality setting.

      I would be very interested in seeing some work done toward more granular compression control via plugins, etc., as my development chops aren’t quite up the task yet.

      0
      • 19

        The reason I myself remove the compression altogether is that we sell themes and we need the highest possible image quality. We do optimize our images ourselves and we really don’t want WordPress to modify things.

        0
        • 20

          Except that if you allow WordPress to alter the dimensions of the image at all, you’ll end up with images that are not optimised. Like I said, if you don’t allow WordPress to alter the dimensions of images you display, that’s fine, but in the vast majority of cases, it’s going to cause problems.

          Christopher is right that WordPress needs better controls for image optimisation, particularly with responsive design requirements becoming ever more important.

          0
  4. 21

    I hate WordPress! Yii Rulez!!!

    0
  5. 22

    Hi,

    Good post, what about doing a tutorial on how to use/setup/develop wordpress as a members site ?

    Regards

    0
  6. 23

    “Mark J. Aquith”? LOL
    Also, for number 13 (Log in as any user), it would be much safer to use the User Switching function in Automattic’s own Developer plugin: http://wordpress.org/plugins/developer

    0
  7. 25

    wp_register_script( $handle, $src, $deps, $ver, $in_footer );

    $in_footer = true allows you to append your script tag to the body instead the head. Default is false.

    0
  8. 26

    #14 has the twitter post var duplicated when setting the facebook and linkedin vars.

    update_user_meta( $user_id, ‘twitter’, $_POST['twitter'] );
    update_user_meta( $user_id, ‘facebook’, $_POST['twitter'] );
    update_user_meta( $user_id, ‘linkedin’, $_POST['twitter'] );

    0
  9. 28

    The code in “11. Upload Files With Ease” isn’t the best way of doing $_FILES upload. wp_upload_bits(). WordPress only using that for the XML-RPC and inside the function wp_generate_attachment_metadata().

    For dealing with file uploads you should use wp_handle_upload(). That does some extra checking since wp_upload_bits() has some flaws. See http://core.trac.wordpress.org/ticket/21292

    You can also use media_handle_upload() depending on the need of the user. Makes things easier then using wp_upload_bits() or wp_handly_upload() since you still need to add the image to WordPress.

    0
  10. 29

    love this tips.awesome !

    0
  11. 30

    Some really usefull tips.

    Thanks for share !!

    0
  12. 31

    Awesome list! Just one thing for #3 : you need a recent version of PHP to get it.

    0
  13. 32

    Wow Really Helpful list. Thank you for posting. :)

    0
  14. 33

    There’s an error in tip #14…

    The last bit of the code should be:
    update_user_meta( $user_id, ‘twitter’, $_POST['twitter'] );
    update_user_meta( $user_id, ‘facebook’, $_POST['facebook'] );
    update_user_meta( $user_id, ‘linkedin’, $_POST['linkedin'] );

    Hope that fixes the issue for everyone.

    0
  15. 34

    Great article and thanks for the tips. You know there’s actually 22, right? You repeated the number 20 twice ;-)

    0
  16. 35

    Great tips and tricks collection, Daniel. Found one yet, to force wordpress to use relative paths for moving from test sites to live sites easier?

    0
    • 36

      Steven – are you not using relative paths in your code? After moving from one environment to another we run the following two queries in mySQL:

      update wp_options set option_value=’http://yourproductionsite.com’ where option_name = ‘home’;

      update wp_options set option_value=’http://yourproductionsite.com’ where option_name = ‘siteurl’;

      0
  17. 37

    This is brilliant, a very helpful read!

    Thanks Daniel

    0
  18. 38

    … thank you! This will really come in handy on my projects

    0
  19. 39

    #21 should be:

    function smashing_buffer_end() {
    ob_end_flush();
    }

    0
  20. 40

    ProTip: Never use WordPress.

    0
  21. 42

    Great list :) Some of them was new to me and I especially got excited by the filter to add shortcodes to textwidgets.. I’ve previously used enhanced text widget plugins, well no more!

    Thought I’d share a nice little snippet which allows you to change the default “Enter title here” text in the title field of a post/page/cpt. A nice feature when using CPT for say events and to be able to set it to “Enter event name here”.


    function change_default_title( $title ){
    $screen = get_current_screen();

    if ( '_your_custom_post_type_' == $screen->post_type ) {
    $title = 'The new title';
    }

    return $title;
    }

    add_filter( 'enter_title_here', 'change_default_title' );

    0
  22. 43

    Okay, you got me on human_time_diff(). Never even occurred to me to check for a function like that. Thanks!

    0
  23. 45

    Nice list! And here is one tip from me:
    I really love shortcodes. And i use really complex shortcodes. The problem is, that you only can return values in a shortcodes. With this snippet you can write your codes with echos and you can call functions etc…

    function my_shortcode($atts, $content = null) {
    ob_start();

    // Start of output

    echo some_function();
    echo ‘some html’;

    // End of output

    $output_string = ob_get_contents();
    ob_end_clean();
    return $output_string;
    }
    add_shortcode(‘my_shortcode’, ‘my_shortcode’);

    0
    • 46

      You could also change|:

      $output_string = ob_get_contents();

      ob_end_clean();

      return $output_string;

      To:

      return ob_get_clean(); // This function does both ob_get_contents() and ob_end_clean().

      0
  24. 47

    FYI: You have two “#20″ items!

    One tip I would have, in general and above all else, is to keep WordPress secure! An older version of WordPress, an outdated plugin, or some other type of gaping hole/security hazard is something you absolutely want to avoid. It sucks when that happens, and it could make all these cool, advanced-level tips moot.

    So always keep backups (and automate them, if you can, to save time), and always make sure your sites are updated. ManageWP, does all of these things, but there are also individual plugins like BackupBuddy, VaultPress, and other plugins work this magic.

    Thanks for the great post!

    0
  25. 48

    Amazing! This is one for the bookmarks, nice work!

    May I suggest to write a post about “Powerful WordPress SQL Queries”. Topics like… Change Site URL, Home URL, GUID, URL in content and most importantly Change admin username and even generate new password. Clearing data like unused tags, pingbacks, spam comments, revisions. Even a trick to export all comment emails without duplicates ;)

    Thanks for reading, if anyone else has some suggestions on this please chime in.

    0
  26. 49

    Here’s a snippet that will disable the default behaviour whereby the list of checkbox items in the Add/Edit Post ‘Categories’ box are reordered to show the selected categories first. This code will respect the original parent/child hierarchy of the categories. Add to your theme’s functions.php file:

    function taxonomy_checklist_checked_ontop_filter($args) {
    $args['checked_ontop'] = false;
    return $args;
    }

    add_filter("wp_terms_checklist_args", "taxonomy_checklist_checked_ontop_filter");

    0
  27. 50

    WOW, most awesome pro tips! Very useful, it’s a lot of very good tweaks to do without installing plugins!

    0
  28. 51

    In your article numbering you listed #20 twice.

    0
  29. 52

    Great article Daniel, WordPress in every update adds many tricks, and some of it wouldn’t be archived on the codex, so the developer need just to focus on the core, analyse the changes and he’ll surely get what he’s looking for. especially when you’re looking for something extra, colorpickers, advanced upload, advanced croping system, crons .. etc.
    Again, Thanks Daniel

    0
  30. 53

    This is an awesome post, it was worth it just for the main wordpress built in script links you posted. I didn’t know it would be so easy to do some of that shit.. Thanks for this post.

    0
  31. 54

    This is very helpful Thanks!!!

    0
  32. 55

    Many thanks! human_time_diff() – it’s awesome

    0
  33. 56

    thanks for your tutorial. but i have a problem with my cart
    i want use ajax with wordpress in cart but i don’t know how to. help with me , plz

    0
  34. 57

    These tips are very useful… Also, just an update.. According to the WordPress Codex, the jpeg_quality filter from tip #3 (Force Perfect JPG Images) is now deprecated. If you want to force perfect images in WP, you should now use wp_editor_set_quality. Hope this helps!

    0
  35. 58

    Very useful information. I’m still somewhat of a newbie at WordPress, so I thank you for the suggestions.

    0
  36. 59

    Such a nice info.Thanks for share this.
    Rehman Ali
    http://www.themesrefinery.com/wordpress-tips-about-htaccess/

    0

Leave a Comment

Yay! You've decided to leave a comment. That's fantastic! Please keep in mind that comments are moderated and rel="nofollow" is in use. So, please do not use a spammy keyword or a domain as your name, or else it will be deleted. Let's have a personal and meaningful conversation instead. Thanks for dropping by!

↑ Back to top