selected

Outputs the html selected attribute.

Description

(string) selected( (mixed) $selected, (constant) $current = true, (bool) $echo = true ); 

Compares the first two arguments and if identical marks as selected

Returns (string)

html attribute or empty string

Parameters (3)

0. $selected (mixed)
One of the values to compare
1. $current — Optional. (constant) => true
(true) The other value to compare if not just true
2. $echo — Optional. (bool) => true
Whether to echo or just return the string

Usage

  1. if ( !function_exists( 'selected' ) ) { 
  2. require_once ABSPATH . WPINC . '/general-template.php'; 
  3.  
  4. // One of the values to compare 
  5. $selected = null; 
  6.  
  7. // (true) The other value to compare if not just true 
  8. $current = true; 
  9.  
  10. // Whether to echo or just return the string 
  11. $echo = true; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = selected($selected, $current, $echo); 
  15.  

Defined (1)

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

/wp-includes/general-template.php  
  1. function selected( $selected, $current = true, $echo = true ) { 
  2. return __checked_selected_helper( $selected, $current, $echo, 'selected' );