do_feed

Load the feed template from the use of an action hook.

Description

do_feed(); 

If the feed action does not have a hook, then the function will die with a message telling the visitor that the feed is not valid.

It is better to only have one hook for each feed.


Usage

  1. if ( !function_exists( 'do_feed' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = do_feed(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function do_feed() { 
  2. global $wp_query; 
  3.  
  4. $feed = get_query_var( 'feed' ); 
  5.  
  6. // Remove the pad, if present. 
  7. $feed = preg_replace( '/^_+/', '', $feed ); 
  8.  
  9. if ( $feed == '' || $feed == 'feed' ) 
  10. $feed = get_default_feed(); 
  11.  
  12. if ( ! has_action( "do_feed_{$feed}" ) ) { 
  13. wp_die( __( ERROR This is not a valid feed template.' ), '', array( 'response' => 404 ) ); 
  14.  
  15. /** 
  16. * Fires once the given feed is loaded. 
  17. * The dynamic portion of the hook name, `$feed`, refers to the feed template name. 
  18. * Possible values include: 'rdf', 'rss', 'rss2', and 'atom'. 
  19. * @since 2.1.0 
  20. * @since 4.4.0 The `$feed` parameter was added. 
  21. * @param bool $is_comment_feed Whether the feed is a comment feed. 
  22. * @param string $feed The feed name. 
  23. */ 
  24. do_action( "do_feed_{$feed}", $wp_query->is_comment_feed, $feed );