remove_theme_support()禁止/删除主题功能支持

目录

描述

Allows a theme to de-register its support of a certain theme feature. Should be called in the theme's functions.php file. Generally would be used for child themes to override support from the parent theme.

remove_theme_support() 描述

用法

<?php remove_theme_support$feature ); ?>

remove_theme_support() 用法

参数

$feature

(string) (必填) Name for the feature being removed.

Features list:

  • 'post-formats'
  • 'post-thumbnails'
  • 'custom-background'
  • 'custom-header'
  • 'automatic-feed-links'
  • 'html5'
  • 'title-tag'
  • 'menus'

默认值: None

remove_theme_support() 参数

返回值

(boolean

Returns true if feature was removed, false otherwise.

remove_theme_support() 返回值

示例

Removing a Feature In a Child Theme

In some cases, a Parent Theme may have activated a feature that you do not want to have available in your Child Theme. For instance, if you are using a parent theme that has activated Featured Images for all Pages and Posts, but you'd like to remove the functionality of having Featured Images for Pages in your Child Theme, you could do something like this:

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

// in your Child Theme's functions.php    

// Use the after_setup_theme hook with a priority of 11 to load after the
// parent theme, which will fire on the default priority of 10
add_action( 'after_setup_theme', 'remove_featured_images_from_child_theme', 11 ); 

function remove_featured_images_from_child_theme() {

    // This will remove support for post thumbnails on ALL Post Types
    remove_theme_support( 'post-thumbnails' );

    // Add this line in to re-enable support for just Posts
    add_theme_support( 'post-thumbnails', array( 'post' ) );
}

remove_theme_support() 示例

历史

  • 添加于 版本: 3.1.0

remove_theme_support() 历史

源文件

remove_theme_support() 函数的代码位于 wp-includes/theme.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Allows a theme to de-register its support of a certain feature
 *
 * Should be called in the theme's functions.php file. Generally would
 * be used for child themes to override support from the parent theme.
 *
 * @since 3.0.0
 * @see add_theme_support()
 * @param string $feature the feature being added
 * @return bool|void Whether feature was removed.
 */
function remove_theme_support( $feature ) {
	// Blacklist: for internal registrations not used directly by themes.
	if ( in_array( $feature, array( 'editor-style', 'widgets', 'menus' ) ) )
		return false;

	return _remove_theme_support( $feature );
}

remove_theme_support() 源文件

相关