atom_entry
云策文档标注
概述
atom_entry 是一个 WordPress 动作钩子,在每个 Atom 订阅源条目末尾触发,允许开发者添加自定义内容或功能。
关键要点
- atom_entry 钩子用于在 Atom 订阅源条目生成时执行自定义代码
- 此钩子自 WordPress 2.0.0 版本引入,无参数传递
- 常用于向 Atom 订阅源条目添加额外元素,如版权信息
代码示例
add_action( 'atom_entry', 'example_1483343_atom_entry', 10 );
function example_1483343_atom_entry() {
printf( '© %1$s %2$s', get_the_date( 'Y' ), get_bloginfo ( 'name' ) );
}注意事项
- 使用此钩子时,需确保代码在 Atom 订阅源上下文中运行,避免影响其他页面
- 示例代码添加了基于发布日期和博客名称的版权信息,开发者可根据需求调整
原文内容
Fires at the end of each Atom feed item.
Source
do_action( 'atom_entry' );
Changelog
| Version | Description |
|---|---|
| 2.0.0 | Introduced. |
Skip to note 2 content
Terri Ann
Example
Adds a rights element to all Atom feed entries.
Uses the post entry’s publication year and the blog name for copyright.
add_action( 'atom_entry', 'example_1483343_atom_entry', 10 ); function example_1483343_atom_entry() { printf( '<rights type="text">© %1$s %2$s</rights>', get_the_date( 'Y' ), get_bloginfo ( 'name' ) ); }