text 一般Wordpress主题设置的基本功能文件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 一般Wordpress主题设置的基本功能文件相关的知识,希望对你有一定的参考价值。
<?php
/**
* Custom Theme functions and definitions.
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package Custom_Theme
*/
/*--------------------------------------------------------------
Custom Admin Logo
--------------------------------------------------------------*/
add_filter('login_headerurl', create_function(false,"return '/';"));
add_action("login_head", "custom_login_logo");
function custom_login_logo() {
echo "
<style>
body.login #login h1 a {
background: url('".get_bloginfo('template_url')."/img/logos/admin-logo.svg') no-repeat scroll center top transparent !important;
background-size: cover;
height: 55px;
width: 320px;
}
body.login {
background: #191919;
}
body.login #login {
padding: 10% 0 0;
}
</style>
";
}
/*----------------------------------------------------------------------
Setup defaults and registers support for various WordPress features.
----------------------------------------------------------------------*/
if ( ! function_exists( 'custom_setup' ) ) :
/*----------------------------------------------------------------------
Sets up theme defaults and registers support for various WordPress
features. Note that this function is hooked into the after_setup_theme
hook, which runs before the init hook. The init hook is too late for
some features, such as indicating support for post thumbnails.
----------------------------------------------------------------------*/
function custom_setup() {
/*----------------------------------------------------------------------
Make theme available for translation. Translations can be filed in the
/languages/ directory. If you're building a theme based on this
theme, use a find and replace to change 'custom-theme' to
the name of your theme in all the template files.
----------------------------------------------------------------------*/
load_theme_textdomain( 'custom-theme', get_template_directory() . '/languages' );
/*----------------------------------------------------------------------
Add default posts and comments RSS feed links to head.
----------------------------------------------------------------------*/
add_theme_support( 'automatic-feed-links' );
/*----------------------------------------------------------------------
Let WordPress manage the document title.
----------------------------------------------------------------------*/
add_theme_support( 'title-tag' );
/*----------------------------------------------------------------------
Enable support for Post Thumbnails on posts and pages.
add_image_size( string $name, int $width, int $height, bool )
ex. custom-size, 220 pixels wide by 180 pixels tall, hard crop mode
----------------------------------------------------------------------*/
add_theme_support( 'post-thumbnails' );
add_image_size( 'custom-size', 220, 180, true );
/*----------------------------------------------------------------------
Removes default image sizes from being created.
----------------------------------------------------------------------*/
function remove_default_image_sizes( $sizes) {
unset( $sizes['thumbnail']);
unset( $sizes['medium']);
unset( $sizes['large']);
return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'remove_default_image_sizes');
/*--------------------------------------------------------------
Menus
--------------------------------------------------------------*/
register_nav_menus( array(
'main_nav' => 'Main Menu',
'secondary_nav' => 'Secondary Menu',
'social_nav' => 'Social Menu',
'footer_nav' => 'Footer Menu',
));
/*----------------------------------------------------------------------
Switch default core markup for search form, comment form, and comments
to output valid HTML5.
----------------------------------------------------------------------*/
add_theme_support( 'html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
));
/*--------------------------------------------------------------
Enqueue scripts and styles.
--------------------------------------------------------------*/
if (!is_admin()) add_action("wp_enqueue_scripts", "custom_scripts", 11);
function custom_scripts() {
wp_enqueue_style( 'style', get_template_directory_uri() . '/css/style.css' );
wp_enqueue_style( 'custom-styles', get_template_directory_uri() . '/layouts/custom-styles.css' );
wp_deregister_script('jquery');
wp_enqueue_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js", array(), false, true);
wp_enqueue_script('overflowVendor', get_template_directory_uri() . '/js/lib/scrolloverflow.js', array( 'jquery' ), false, true);
wp_enqueue_script('plugin', get_template_directory_uri() . '/js/plugins.js', array( 'jquery' ), false, true);
wp_enqueue_script('scripts', get_template_directory_uri() . '/js/scripts.js', array( 'jquery' ), false, true);
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
/*--------------------------------------------------------------
ACF Options Page
--------------------------------------------------------------*/
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'Theme General Settings',
'menu_title' => 'Theme Settings',
'menu_slug' => 'theme-general-settings',
'capability' => 'edit_posts',
'redirect' => false
));
acf_add_options_sub_page(array(
'page_title' => 'Theme Header Settings',
'menu_title' => 'Header',
'parent_slug' => 'theme-general-settings',
));
acf_add_options_sub_page(array(
'page_title' => 'Theme Footer Settings',
'menu_title' => 'Footer',
'parent_slug' => 'theme-general-settings',
));
}
}
endif;
add_action( 'after_setup_theme', 'custom_setup' );
/*--------------------------------------------------------------
SVG Support for Wordpress
--------------------------------------------------------------*/
function cc_mime_types($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
/*--------------------------------------------------------------
Update CSS within in Admin
--------------------------------------------------------------*/
function admin_style() {
wp_enqueue_style( 'admin-style', get_template_directory_uri() . '/css/admin.css' );
}
add_action('admin_enqueue_scripts', 'admin_style');
/*--------------------------------------------------------------
Custom Post Types
--------------------------------------------------------------*/
function custom_post_type () {
register_post_type( 'work',
array(
'labels' => array(
'name' => __( 'Work Sample' ),
'singular_name' => __( 'Work Sample' ),
'add_new' => __( 'Add New Work Sample' ),
'add_new_item' => __( 'Add New Work Sample' ),
'new_item' => __( 'New Work Sample' ),
'edit_item' => __( 'Edit Work Sample' ),
'view_item' => __( 'View Work Sample' )
),
'menu_position' => 20,
'menu_icon' => 'dashicons-analytics',
'show_in_nav_menus' => true,
'public'=> true,
'supports' => array( 'title', 'thumbnail'),
'taxonomies' => array( 'category'),
'hierarchical' => true
)
);
}
add_action( 'init', 'custom_post_type', 0 );
/*--------------------------------------------------------------
Custom Columns
--------------------------------------------------------------*/
function work_column_label($columns)
{
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => 'Title',
'client' => 'Client',
'categories' => 'Category',
'date' => 'Date',
);
return $columns;
}
function work_column_content($column)
{
global $post;
if ($column == 'client') {
if(get_field('client')) {
$post = get_field('client', $post->ID);
setup_postdata( $post );
echo the_title();
wp_reset_postdata();
} else {
echo 'None';
}
}
}
add_action("manage_pages_custom_column", "work_column_content");
add_filter("manage_edit-work_columns", "work_column_label");
/*--------------------------------------------------------------
Removes a class from the body_class array.
--------------------------------------------------------------*/
add_filter( 'body_class', function( $classes ) {
if ( isset( $classes['customize-support'] ) ) {
unset( $classes['customize-support'] );
}
return $classes;
} );
/*--------------------------------------------------------------
Custom theme option styles
--------------------------------------------------------------*/
function generate_options_css() {
$ss_dir = get_stylesheet_directory();
ob_start(); // Capture all output into buffer
require($ss_dir . '/inc/custom-styles.php'); // Grab the custom-style.php file
$css = ob_get_clean(); // Store output in a variable, then flush the buffer
file_put_contents($ss_dir . '/layouts/custom-styles.css', $css, LOCK_EX); // Save it as a css file
}
add_action( 'acf/save_post', 'generate_options_css' ); //Parse the output and write the CSS file on post save
/*--------------------------------------------------------------
Custom ACF Styles and Scripts
--------------------------------------------------------------*/
function my_acf_admin_head()
{ ?>
<style type="text/css">
.wp-asset-icon img {
min-width: 300px;
}
</style>
<script type="text/javascript">
(function($){
/* ... */
})(jQuery);
</script>
<?php }
add_action('acf/input/admin_head', 'my_acf_admin_head');
/*--------------------------------------------------------------
Removes admin margin-top
--------------------------------------------------------------*/
add_action('get_header', 'my_filter_head');
function my_filter_head() {
remove_action('wp_head', '_admin_bar_bump_cb');
}
以上是关于text 一般Wordpress主题设置的基本功能文件的主要内容,如果未能解决你的问题,请参考以下文章