#17: paginate_links

The paginate_links filter allows you to modify the current pagination link. Since no context is passed to the filter, it will need to be handled in your callback unless the intent is to globally affect pagination links.

It is evaluated in paginate_links() in the wp-includes/general-template.php file.

paginate_links accepts a single argument in the form a string containing the paginated link.

Example:

There is no example for this filter yet. Submit one.

One idea might to pass a custom query var for certain contexts.

#16: page_link

The page_link filter allows you to do change the permalink returned for the current page when using get_permalink(). When get_permalink() is used with pages, it employs get_page_link(), which respects the show_on_front and page_on_front options. This means that if the current page is set as your front page, the permalink returned will be the home_url().

The filter is evaluated in get_page_link() in the wp-includes/link-template.php file.

page_link accepts 3 arguments:

  1. string $link the page link
  2. int $post_id the page id
  3. bool $sample whether or not to return a ‘sample’ permalink

Example:

Let’s say that for some reason, you have a page set as your front page but you want to return the page’s actual permalink when using get_permalink(). The following checks the show_on_front and page_on_front options to see if there’s a match, and if there is, returns the actual permalink instead.

Note: this has the possibility of wreaking havoc on how WordPress determines a ‘Home’ link in menus as well as how the front page may be determined.

View the code example on Gist.

#15: the_content

The the_content filter makes it possible to modify the content of a post, page or other post type. It is probably one of the most commonly-used — and misused — filter hooks in the WordPress code base.

Misuse of the_content is rampant largely due to the geography of a post’s content on the page. Developers want something to show up at the end of the post so sometimes they’ll use this hook to accomplish that placement. Unfortunately, whatever it is they’re hooking onto the beginning or end of the_content often has little or nothing to do with the post itself.

It’s one of those filters where you can look to ‘how Core does it’ to really see its intended purpose. Out of the box, Core filters the_content in about 10 different places. This is to accomplish much of the behind-the-scenes post cleanup users never really see, which include:

  • oEmbed handling
  • converting smilies to images
  • removing unwanted characters
  • auto-adding paragraph tags
  • processing shortcodes
  • and more

In all such cases, Core filters the post content itself, but doesn’t tack on unrelated stuff.

the_content is evaluated in:

It accepts a single argument, a string containing the post’s content.

Example:

Let’s say you’re one of those people who just can’t get out of the habit of using two spaces after periods and you’ve been writing on your blog for years. The following will filter the_content to convert those pesky double spaces to singles.

View the code example on Gist.