This WordPress function registers theme support for a given feature. add_theme_support must be called in your theme’s functions.php file to work.
Below is the syntax of add_theme_support()
Function, how to use in your WordPress plugin or theme file.
Syntax:
1 |
add_theme_support( string $feature ) |
Used Parameters:
$feature
: (string) (Required) The feature being added. Likely core values include ‘post-formats’, ‘post-thumbnails’, ‘html5’, ‘custom-logo’, ‘custom-header-uploads’, ‘custom-header’, ‘custom-background’, ‘title-tag’, ‘starter-content’, etc.
This function is available inside the File: wp-includes/category-template.php. You can find the function described below:
1 2 3 4 5 6 7 8 9 |
function get_the_category_by_ID( $cat_ID ) { $cat_ID = (int) $cat_ID; $category = get_term( $cat_ID, 'category' ); if ( is_wp_error( $category ) ) return $category; return ( $category ) ? $category->name : ''; } |
Example 1:
1 2 3 4 5 6 7 8 9 |
function field_value( $data ) { if ( $data == -1 ) return false; if ( is_numeric( $data ) ) return get_the_category_by_ID( intval( $data ) ); return $data; } |
Example 2:
1 2 3 4 5 6 7 8 9 10 11 |
function the_category_head($before = '', $after = '') { global $post, $currentcat, $previouscat, $dateformat, $newday; $currentcat = $post->post_category; if ($currentcat != $previouscat) { echo $before; echo get_the_category_by_ID($currentcat); echo $after; $previouscat = $currentcat; } } |
Example 3:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
function check_for_category_single_template($t) { foreach ((array) get_the_category() as $cat) { if (file_exists(TEMPLATEPATH . "/single-{$cat->slug}.php")) { return TEMPLATEPATH . "/single-{$cat->slug}.php"; } if ($cat->parent) { $cat = get_the_category_by_ID($cat->parent); if (file_exists(TEMPLATEPATH . "/single-{$cat->slug}.php")) { return TEMPLATEPATH . "/single-{$cat->slug}.php"; } } } return $t; } |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.