Hooks and Filters

Hooks and filters are the main way that WordPress is extended and we’ve built a few of these into the WP-Drudge template to make extending the template easier. Hooks are used to add functionality to certain parts of the theme while filters are used to change text or data as it passes through the flow of the theme.

In order to help people understand how some of these are working, I put together a sample plugin that uses some of the hooks and filters below. Installing and activating this plugin won’t actually do anything unless you change some of values its returning. This should give you a good start modifying some of the core WP-Drudge functionality without changing the theme code.

Download
or view on GitHub

For more information on using hooks and filters, see this Smashing Magazine article on actions and filters.

Filters

  • wpd_theme_settings – the theme settings are passed through this filter; you can use this filter to add or remove WP-Drudge settings from the options page (added in version 2.3.2)
  • wpd_theme_settings_output – companion to the filter above, allows you to change settings on output
  • wpd_404_text – the text shown on the 404 page, a page that’s shown when a link on the site is not found (a text field will be added to the Text tab of the options page in version 2.7.1)
  • wpdrudge_archive_page_title – this is the title of the archive page, which changes based on what page is being shown (a text field was added to the Text tab of the options page in version 2.5.1)
  • wpdrudge_home_link – the text used for the link back to the homepage on various pages (a text field was added to the Text tab of the options page in version 2.4)

Filters – metas

  • wpd_post_metas – the post metas are passed through this filter; you can use this filter to add or remove meta fields on the post edit screen
  • wpd_link_text – the link for the post, usually the permalink … poorly named
  • wpd_link_out_text – the outbound link URL, if any  … poorly named
  • wpd_title_text_raw – the title text is passed through this filter before any transformations
  • wpd_title_text – the link headline is passed through this filter before being displayed
  • wpd_link_css – both the link insert and link CSS are passed through this filter before being applied
  • wpd_link_insert – the HTML inserted into the link tag; valid HTML attributes here (adding v2.4)
  • wpd_blurb_text –  the blurb text is passed through this filter before being displayed
  • wpd_date_text – the posted date is passed through this filter before being displayed
  • wpd_comment_text – the comment link text is passed through this filter before being displayed
  • wpd_imgsize_feat – image size, in pixels for the featured image, overrides the setting on the options page
  • wpd_imgsize_single – image size, in pixels for the single post page image, overrides the setting on the options page
  • wpd_imgsize_posted – image size, in pixels for the widget post image, overrides the setting on the options page
  • wpd_caption_text – image caption text is passed through this filter before being displayed
  • wpd_image – the plain text URL for the image to display
  • wpd_processed_link – the final, processed link array is passed through this filter before being used on the site

Hooks

  • wpd_hook_before_content – called before the content on all pages
  • wpd_hook_after_content – called after the content on all pages
  • wpd_hook_site_top – called at the very beginning of the theme display
  • wpd_hook_header_top – called before the logo/tagline combo, within the header element (not used on mobile page template)
  • wpd_hook_header_middle – called after the logo/tagline combo (not used on mobile page template)
  • wpd_hook_header_bottom – called after the main navigation, within the header element (not used on mobile page template)

Hooks – specific

  • wpd_hook_single_post_top – called before the content on a single post page
  • wpd_hook_single_post_bottom – called after the content on a single post page
  • wpd_hook_featured_before – called before all featured items are displayed, within the main wrapper element
  • wpd_hook_featured_after – called after all featured items are displayed, within the main wrapper element

Hooks – widgets

  • wpd_hook_before_posted_link_widget – called at the beginning of each Posted Link widget
  • wpd_hook_after_posted_link_widget – called at the end of each Posted Link widget
  • wpd_hook_before_posted_link – called at the beginning of each Posted Link item
  • wpd_hook_after_posted_link – called at the end of each Posted Link item