WordPress Code Snippets

Code snippets are a simple way to add features and functionality to your WordPress website. They are just a cut-n-paste away. Here is a collection of the most useful WordPress snippets on the Internet.

Display Popular Posts by Comment Count

The following snippet can be used to show the posts with the highest number of comments. It displays the posts in a list, but could easily be customized. <?php $popular_posts = $wpdb->get_results(“SELECT id, post_title, comment_count FROM {$wpdb->prefix}posts WHERE post_type=’post’ ORDER BY comment_count DESC LIMIT 10″); ?> <ul> <?php foreach($popular_posts as $post) : ?> <li> <?php [...]

Add an Edit Link to your Posts and Pages

Displays a link to edit the current post, if a user is logged in and allowed to edit the post. It must be used within The Loop. <?php edit_post_link(__(‘Edit This’)); ?> Source

Easy Post Pagination, Multiple Page Posts

You can easily breakup long posts into multiple pages. The trick is to use the <!–nextpage–> shortcode. This can help with the flow and break long posts into more digestible chunks. <!–nextpage–> You can see it in action below.

Pages: 1 2 3