我已将以下代码放入functions.php
文件中:
function my_theme_enqueue_styles() {
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/assets/css/style.min.css',
array( $parent_style ),
wp_get_theme()->get('Version')
);
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
上面的代码导致我在标题中加载样式/脚本。如何让上面的代码加载到页脚内呢?有人能帮助我吗?
答案 0 :(得分:1)
不确定为什么要将样式和脚本加载到页脚中,而不是在页眉中。也就是说,只需将以下代码放入@RequestMapping(value = "/{collection}/branches", method = RequestMethod.GET)
public ResponseEntity<CollectionApi<BranchApi>> getBranches(@PathVariable String collection,
@RequestParam(defaultValue = ModelsController.DEF_OFFSET) Long _offset,
@RequestParam(defaultValue = ModelsController.DEF_LIMIT) Integer _limit,
@RequestParam(required = false) String rep,
@RequestParam(defaultValue = ModelsController.DEF_SYNC) Integer _sync) {
try {
CollectionApi<BranchApi> branches = branchesService.getBranches(collection);
if (branches == null) {
throw new NotFoundException("Collection not found");
}
return ResponseEntity.ok(branches);
} catch (NucleusModelingException e) {
throw new BadRequestException(e.getLocalizedMessage(), e);
}
}
@RequestMapping(value = "/{collection}/branches", method = RequestMethod.PUT)
public ResponseEntity<CollectionApi<BranchApi>> setActiveBranch(
@PathVariable String collection,
@RequestParam String branch) {
try {
CollectionApi<BranchApi> branches = branchesService.setActiveBranch(collection, branch);
return ResponseEntity.ok(branches);
} catch (NucleusModelingException e) {
throw new BadRequestException(e.getLocalizedMessage(),e);
}
}
@RequestMapping(value = "/{collection}/branches", method = RequestMethod.POST)
public ResponseEntity<CollectionApi<BranchApi>> createBranch(
@PathVariable String collection,
@RequestParam String branch) {
try {
CollectionApi<BranchApi> branches = branchesService.checkoutBranch(collection, branch);
return ResponseEntity.status(HttpStatus.CREATED).body(branches);
} catch (NucleusModelingException e) {
throw new BadRequestException(e.getLocalizedMessage(),e);
}
}
文件中:
functions.php
如果您不是主题作者,则应首先创建Child Theme。否则,只要处理主题更新,您的修改就会丢失。
答案 1 :(得分:1)
在<head>
标记之外输出样式是无效的HTML,这样做是不好的做法。
然而,WordPress仍然使我们能够使用print_late_styles()函数将页脚中的样式排入队列。这会打印排队等待HTML头的样式太晚。
答案 2 :(得分:1)
在页脚中输出CSS并不完全正确。但是,如果是脚本,wp_enqueue_script
有第5个参数,$in_footer
接受TRUE/FALSE
,它会完全按照您的要求执行TRUE
。