添加 Genesis 作者框内容包装器
Add Genesis author box content wrapper
我需要在作者框中的所有内容周围添加一个包装器 div。
需要什么过滤代码才能把genesis_author_box改成这样:
<section class="author-box" itemprop="author" itemscope="" itemtype="https://schema.org/Person">
<div class="author-box-wrap">
<img alt="" src="" srcset="" class="avatar avatar-150 photo" height="150" width="150">
<h4 class="author-box-title">About <span itemprop="name">Author Name</span></h4>
<div class="author-box-content" itemprop="description">Description Text</div>
</div>
</section>
这是默认的 Genesis 标记:
<section class="author-box" itemprop="author" itemscope="" itemtype="https://schema.org/Person">
<img alt="" src="" srcset="" class="avatar avatar-150 photo" height="150" width="150">
<h4 class="author-box-title">About <span itemprop="name">Author Name</span></h4>
<div class="author-box-content" itemprop="description">Description Text</div>
</section>
这是组装默认 Genesis 标记的代码:
/**
* Echo the the author box and its contents.
*
* The title is filterable via `genesis_author_box_title`, and the gravatar size is filterable via
* `genesis_author_box_gravatar_size`.
*
* The final output is filterable via `genesis_author_box`, which passes many variables through.
*
* @since 1.3.0
*
* @global WP_User $authordata Author (user) object.
*
* @param string $context Optional. Allows different author box markup for different contexts, specifically 'single'.
* Default is empty string.
* @param bool $echo Optional. If true, the author box will echo. If false, it will be returned.
* @return string HTML for author box if `$echo` param is falsy.
*/
function genesis_author_box( $context = '', $echo = true ) {
global $authordata;
$authordata = is_object( $authordata ) ? $authordata : get_userdata( get_query_var( 'author' ) );
$gravatar_size = apply_filters( 'genesis_author_box_gravatar_size', 70, $context );
$gravatar = get_avatar( get_the_author_meta( 'email' ), $gravatar_size );
$description = wpautop( get_the_author_meta( 'description' ) );
// The author box markup, contextual.
if ( genesis_html5() ) {
$title = __( 'About', 'genesis' ) . ' <span itemprop="name">' . get_the_author() . '</span>';
/**
* Author box title filter.
*
* Allows you to filter the title of the author box. $context passed as second parameter to allow for contextual filtering.
*
* @since unknown
*
* @param string $title Assembled Title.
* @param string $context Context.
*/
$title = apply_filters( 'genesis_author_box_title', $title, $context );
$heading_element = 'h1';
if ( 'single' === $context && ! genesis_get_seo_option( 'semantic_headings' ) ) {
$heading_element = 'h4';
} elseif ( genesis_a11y( 'headings' ) || get_the_author_meta( 'headline', (int) get_query_var( 'author' ) ) ) {
$heading_element = 'h4';
}
$pattern = sprintf( '<section %s>', genesis_attr( 'author-box' ) );
$pattern .= '%s<' . $heading_element . ' class="author-box-title">%s</' . $heading_element . '>';
$pattern .= '<div class="author-box-content" itemprop="description">%s</div>';
$pattern .= '</section>';
} else {
$title = apply_filters( 'genesis_author_box_title', sprintf( '<strong>%s %s</strong>', __( 'About', 'genesis' ), get_the_author() ), $context );
$pattern = '<div class="author-box">%s<h1>%s</h1><div>%s</div></div>';
if ( 'single' === $context || get_the_author_meta( 'headline', (int) get_query_var( 'author' ) ) ) {
$pattern = '<div class="author-box"><div>%s %s<br />%s</div></div>';
}
}
$output = sprintf( $pattern, $gravatar, $title, $description );
/**
* Author box output filter.
*
* Allows you to filter the full output of the author box.
*
* @since unknown
*
* @param string $output Assembled output.
* @param string $context Context.
* @param string $pattern (s)printf pattern.
* @param string $context Gravatar.
* @param string $context Title.
* @param string $context Description.
*/
$output = apply_filters( 'genesis_author_box', $output, $context, $pattern, $gravatar, $title, $description );
if ( $echo ) {
echo $output;
return null;
} else {
return $output;
}
我的PHP真的很粗糙...谢谢大家的帮助!
试一试:
add_filter( 'genesis_author_box', 'my_filter_author_box', 10, 3 );
function my_filter_author_box( $output, $context ) {
$output = preg_replace( '/<section (.+?)>(.+)<\/section>/ms', '<section ><div class="author-box-wrap"></div></section>', $output );
return $output;
}
可能值得重新考虑为什么需要添加内包装 div
并看看是否可以找到更好的样式来代替它。
我需要在作者框中的所有内容周围添加一个包装器 div。
需要什么过滤代码才能把genesis_author_box改成这样:
<section class="author-box" itemprop="author" itemscope="" itemtype="https://schema.org/Person">
<div class="author-box-wrap">
<img alt="" src="" srcset="" class="avatar avatar-150 photo" height="150" width="150">
<h4 class="author-box-title">About <span itemprop="name">Author Name</span></h4>
<div class="author-box-content" itemprop="description">Description Text</div>
</div>
</section>
这是默认的 Genesis 标记:
<section class="author-box" itemprop="author" itemscope="" itemtype="https://schema.org/Person">
<img alt="" src="" srcset="" class="avatar avatar-150 photo" height="150" width="150">
<h4 class="author-box-title">About <span itemprop="name">Author Name</span></h4>
<div class="author-box-content" itemprop="description">Description Text</div>
</section>
这是组装默认 Genesis 标记的代码:
/**
* Echo the the author box and its contents.
*
* The title is filterable via `genesis_author_box_title`, and the gravatar size is filterable via
* `genesis_author_box_gravatar_size`.
*
* The final output is filterable via `genesis_author_box`, which passes many variables through.
*
* @since 1.3.0
*
* @global WP_User $authordata Author (user) object.
*
* @param string $context Optional. Allows different author box markup for different contexts, specifically 'single'.
* Default is empty string.
* @param bool $echo Optional. If true, the author box will echo. If false, it will be returned.
* @return string HTML for author box if `$echo` param is falsy.
*/
function genesis_author_box( $context = '', $echo = true ) {
global $authordata;
$authordata = is_object( $authordata ) ? $authordata : get_userdata( get_query_var( 'author' ) );
$gravatar_size = apply_filters( 'genesis_author_box_gravatar_size', 70, $context );
$gravatar = get_avatar( get_the_author_meta( 'email' ), $gravatar_size );
$description = wpautop( get_the_author_meta( 'description' ) );
// The author box markup, contextual.
if ( genesis_html5() ) {
$title = __( 'About', 'genesis' ) . ' <span itemprop="name">' . get_the_author() . '</span>';
/**
* Author box title filter.
*
* Allows you to filter the title of the author box. $context passed as second parameter to allow for contextual filtering.
*
* @since unknown
*
* @param string $title Assembled Title.
* @param string $context Context.
*/
$title = apply_filters( 'genesis_author_box_title', $title, $context );
$heading_element = 'h1';
if ( 'single' === $context && ! genesis_get_seo_option( 'semantic_headings' ) ) {
$heading_element = 'h4';
} elseif ( genesis_a11y( 'headings' ) || get_the_author_meta( 'headline', (int) get_query_var( 'author' ) ) ) {
$heading_element = 'h4';
}
$pattern = sprintf( '<section %s>', genesis_attr( 'author-box' ) );
$pattern .= '%s<' . $heading_element . ' class="author-box-title">%s</' . $heading_element . '>';
$pattern .= '<div class="author-box-content" itemprop="description">%s</div>';
$pattern .= '</section>';
} else {
$title = apply_filters( 'genesis_author_box_title', sprintf( '<strong>%s %s</strong>', __( 'About', 'genesis' ), get_the_author() ), $context );
$pattern = '<div class="author-box">%s<h1>%s</h1><div>%s</div></div>';
if ( 'single' === $context || get_the_author_meta( 'headline', (int) get_query_var( 'author' ) ) ) {
$pattern = '<div class="author-box"><div>%s %s<br />%s</div></div>';
}
}
$output = sprintf( $pattern, $gravatar, $title, $description );
/**
* Author box output filter.
*
* Allows you to filter the full output of the author box.
*
* @since unknown
*
* @param string $output Assembled output.
* @param string $context Context.
* @param string $pattern (s)printf pattern.
* @param string $context Gravatar.
* @param string $context Title.
* @param string $context Description.
*/
$output = apply_filters( 'genesis_author_box', $output, $context, $pattern, $gravatar, $title, $description );
if ( $echo ) {
echo $output;
return null;
} else {
return $output;
}
我的PHP真的很粗糙...谢谢大家的帮助!
试一试:
add_filter( 'genesis_author_box', 'my_filter_author_box', 10, 3 );
function my_filter_author_box( $output, $context ) {
$output = preg_replace( '/<section (.+?)>(.+)<\/section>/ms', '<section ><div class="author-box-wrap"></div></section>', $output );
return $output;
}
可能值得重新考虑为什么需要添加内包装 div
并看看是否可以找到更好的样式来代替它。