希望创建一个自定义字段来更改博客存档页上显示的标题,而不影响实际帖子的标题。(这样做的目的是在查看所有帖子时使用较短的标题)
我在博客布局中发现了以下代码行。php。
<div class="fusion-post-content post-content">
<?php // Render the post title. ?>
<?php echo wp_kses_post( avada_render_post_title( get_the_ID() ) ); ?>
<?php // Render post meta for grid and timeline layouts. ?>
<?php if ( \'grid\' === $blog_layout || \'timeline\' === $blog_layout ) : ?>
<?php echo wp_kses_post( avada_render_post_metadata( \'grid_timeline\' ) ); ?>
<?php if ( ( Avada()->settings->get( \'post_meta\' ) && ( Avada()->settings->get( \'post_meta_author\' ) || Avada()->settings->get( \'post_meta_date\' ) || Avada()->settings->get( \'post_meta_cats\' ) || Avada()->settings->get( \'post_meta_tags\' ) || Avada()->settings->get( \'post_meta_comments\' ) || Avada()->settings->get( \'post_meta_read\' ) ) ) && 0 < Avada()->settings->get( \'excerpt_length_blog\' ) ) : ?>
<div class="fusion-content-sep"></div>
<?php endif; ?>
<?php elseif ( \'large-alternate\' === $blog_layout || \'medium-alternate\' === $blog_layout ) : ?>
<?php // Render post meta for alternate layouts. ?>
<?php echo wp_kses_post( avada_render_post_metadata( \'alternate\' ) ); ?>
<?php endif; ?>
<div class="fusion-post-content-container">
<?php
/**
* The avada_blog_post_content hook.
*
* @hooked avada_render_blog_post_content - 10 (outputs the post content wrapped with a container).
*/
do_action( \'avada_blog_post_content\' );
?>
</div>
</div>
编辑:还找到了实际功能:function avada_render_post_title( $post_id = \'\', $linked = true, $custom_title = \'\', $custom_size = \'2\', $custom_link = \'\' ) {
$entry_title_class = \'\';
// Add the entry title class if rich snippets are enabled.
if ( Avada()->settings->get( \'disable_date_rich_snippet_pages\' ) ) {
$entry_title_class = \' class="entry-title fusion-post-title"\';
} else {
$entry_title_class = \' class="fusion-post-title"\';
}
// If we have a custom title, use it otherwise get post title.
$title = ( $custom_title ) ? $custom_title : get_the_title( $post_id );
$permalink = ( $custom_link ) ? $custom_link : get_permalink( $post_id );
// If the post title should be linked at the markup.
if ( $linked ) {
$link_target = \'\';
if ( \'yes\' == fusion_get_page_option( \'link_icon_target\', $post_id ) || \'yes\' == fusion_get_page_option( \'post_links_target\', $post_id ) ) {
$link_target = \' target="_blank" rel="noopener noreferrer"\';
}
$title = \'<a href="\' . $permalink . \'"\' . $link_target . \'>\' . $title . \'</a>\';
}
// Return the HTML markup of the post title.
return \'<h\' . $custom_size . $entry_title_class . \'>\' . $title . \'</h\' . $custom_size . \'>\';
}
我的第一个想法是,更改get\\u the\\u ID()参数应该可以做到这一点,但在添加伪文本之后,它似乎没有改变任何东西。这是应该找的地方吗?
编辑:
非常了解挂钩,但下面是我使用mikesar提供的代码失败的尝试:
add_filter( \'avada_render_post_title\', \'short_title_replace\' );
function short_title_replace(){
$customTitle = get_post_meta( get_the_ID(), \'short-title\', true );
if ( ! empty( $customTitle ) ) {
echo $customTitle;
} else {
echo wp_kses_post( avada_render_post_title( get_the_ID() ) );
}
}
我已经创建了自定义字段,但不确定如何连接到avada_render_post_title函数。