无法启用特色图片

Unable to enable Feature Image

先说我不知道​​PHP。 我一直在网上搜索以寻找在我的帖子中启用 "Feature Image" 的方法。一些消息来源建议将 add_theme_support( 'post-thumbnails' ); 放在我主题的 functions.php 文件中。没有成功。

我在下面粘贴了functions.php的内容。感谢您提供的任何帮助!

<?php

//Repeating fields
include_once('acf-repeater/acf-repeater.php');

//Add custom styles to WP editor
add_filter( 'mce_buttons_2', 'my_mce_buttons_2' );

function my_mce_buttons_2( $buttons ) {
    array_unshift( $buttons, 'styleselect' );
    return $buttons;
}

add_filter( 'tiny_mce_before_init', 'my_mce_before_init' );

add_theme_support( 'post-thumbnails' );

function my_mce_before_init( $settings ) {

    $style_formats = array(
        array(
            'title' => 'Theme Blue',
            'inline' => 'span',
            'classes' => 'theme-blue',
            'wrapper' => true
        ),
        array(
            'title' => 'Theme Blue (Background Colour)',
            'inline' => 'span',
            'classes' => 'theme-blue-bg',
            'wrapper' => true
        ),
        array(
            'title' => 'Theme Red',
            'inline' => 'span',
            'classes' => 'theme-red',
            'wrapper' => true
        ),
        array(
            'title' => 'Theme Red (Background Colour)',
            'inline' => 'span',
            'classes' => 'theme-red-bg',
            'wrapper' => true
        ),
        array(
            'title' => 'Theme Green',
            'inline' => 'span',
            'classes' => 'theme-green',
            'wrapper' => true
        ),
        array(
            'title' => 'Theme Green (Background Colour)',
            'inline' => 'span',
            'classes' => 'theme-green-bg',
            'wrapper' => true
        ),
        array(
            'title' => 'Theme Darker Green',
            'inline' => 'span',
            'classes' => 'theme-darker-green',
            'wrapper' => true
        ),
        array(
            'title' => 'Theme Darker Green (Background Colour)',
            'inline' => 'span',
            'classes' => 'theme-darker-green-bg',
            'wrapper' => true
        ),
        array(
            'title' => 'Theme Purple',
            'inline' => 'span',
            'classes' => 'theme-purple',
            'wrapper' => true
        ),
        array(
            'title' => 'Theme Purple (Background Colour)',
            'inline' => 'span',
            'classes' => 'theme-purple-bg',
            'wrapper' => true
        ),
        array(
            'title' => 'Solutions (Red Stats box)',
            'block' => 'div',
            'classes' => 'video-stats theme-red-bg',
            'wrapper' => true
        ),      
        array(
            'title' => 'Solutions (Green Stats box)',
            'block' => 'div',
            'classes' => 'video-stats theme-green-bg',
            'wrapper' => true
        ),  
        array(
            'title' => 'Solutions (Blue Stats box)',
            'block' => 'div',
            'classes' => 'video-stats theme-blue-bg',
            'wrapper' => true
        ),  
        array(
            'title' => 'Solutions (DarkerGreen Stats box)',
            'block' => 'div',
            'classes' => 'video-stats theme-darker-green-bg',
            'wrapper' => true
        ),  
        array(
            'title' => 'Solutions (Add Padding Below Last Stats box in group)',
            'selector' => 'div',
            'classes' => 'last-container'
        ), 
        array(
            'title' => 'Solutions (Enlarged Numbers)',
            'inline' => 'span',
            'classes' => 'highlight',
            'wrapper' => true
        ), 
        array(
            'title' => 'Increase Text Size',
            'inline' => 'span',
            'classes' => 'highlight',
            'wrapper' => true
        ), 
        array(
            'title' => 'Decrease Text Size (Source: etc.)',
            'inline' => 'span',
            'classes' => 'source',
            'wrapper' => true
        ), 
        array(
            'title' => 'Red Highlight',
            'inline' => 'span',
            'classes' => 'red-highlight',
            'wrapper' => true
        ),
        array(
            'title' => 'Quote',
            'selector' => 'p',
            'classes' => 'quote'
        ), 
        array(
            'title' => 'Author',
            'selector' => 'p',
            'classes' => 'author'
        ),
        array(
            'title' => 'List Spacer (apply to P above lists)',
            'selector' => 'p',
            'classes' => 'faux-list-header'
        ) 
    );

    $settings['style_formats'] = json_encode( $style_formats );

    return $settings;

}

add_editor_style('custom-editor-style.css');  
add_action( 'admin_init', 'add_my_editor_style' );

function add_my_editor_style() {
    add_editor_style();
}

function remove_acf_menu()
{

    $admins = array( 
        'admin'
    );

    $current_user = wp_get_current_user();

    if( !in_array( $current_user->user_login, $admins ) )
    {
        remove_menu_page('edit.php?post_type=acf');
        remove_menu_page('admin.php?page=wpfront-plugins');
        remove_menu_page('user-edit.php?user_id=1');
    }

}
add_action( 'admin_menu', 'remove_acf_menu', 999 );

您只是缺少调用的第二个参数:

add_theme_support( 'post-thumbnails', array( 'post' ) ); 

这将为 post 启用精选图片。如果你想在页面上添加它们,请将 post 更改为 page.

编辑第二个参数需要是数组