如果可能的话,用你的方法会很棘手。您可以使用具有灵活维度的自定义标题。这将允许用户上传标题图像,然后根据需要轻松裁剪。
// Register Theme Features
function custom_theme_features() {
// Add theme support for Custom Header
$header_args = array(
\'default-image\' => \'http://example.com/image.png\',
\'width\' => 0,
\'height\' => 0,
\'flex-width\' => true,
\'flex-height\' => true,
\'random-default\' => false,
\'header-text\' => false,
\'default-text-color\' => \'\',
\'uploads\' => true,
);
add_theme_support( \'custom-header\', $header_args );
}
// Hook into the \'after_setup_theme\' action
add_action( \'after_setup_theme\', \'custom_theme_features\' );