Skip to content

Instantly share code, notes, and snippets.

@Danilfilatov
Last active September 8, 2019 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Danilfilatov/df5adf5a1a4d39a306c31c4ae481a030 to your computer and use it in GitHub Desktop.
Save Danilfilatov/df5adf5a1a4d39a306c31c4ae481a030 to your computer and use it in GitHub Desktop.
Wordpress Divi theme fix - show tags in Blog module + single post
/* (Go to Appearance > Editor) */
/* Code in this file and in the Blog-2.php go to Divi/includes/builder/module/Blog.php - they'll be overwritten if you update Divi. */
/* Search for class="post-meta" and you'll find two matches - one for the visual builder module version, the second for the output on the live website. */
/* Paste this code in the place of the first match (delete the old code in the file first): */
printf( '<p class="post-meta">%1$s %2$s %3$s %4$s %5$s %6$s %7$s %8$s %9$s</p>',
(
'on' === $args['show_author']
? et_get_safe_localization( sprintf( __( 'by %s', 'et_builder' ), '<span class="author vcard">' . et_pb_get_the_author_posts_link() . '</span>' ) )
: ''
),
(
( 'on' === $args['show_author'] && 'on' === $args['show_date'] )
? ' | '
: ''
),
(
'on' === $args['show_date']
? et_get_safe_localization( sprintf( __( '%s', 'et_builder' ), '<span class="published">' . esc_html( get_the_date( $args['meta_date'] ) ) . '</span>' ) )
: ''
),
(
(( 'on' === $args['show_author'] || 'on' === $args['show_date'] ) && 'on' === $args['show_categories'] )
? ' | '
: ''
),
(
'on' === $args['show_categories']
? get_the_category_list(', ')
: ''
),
(
(( 'on' === $args['show_author'] || 'on' === $args['show_date'] || 'on' === $args['show_categories'] ) && 'on' === $args['show_comments'])
? ' | '
: ''
),
(
'on' === $args['show_comments']
? sprintf( esc_html( _nx( '%s Comment', '%s Comments', get_comments_number(), 'number of comments', 'et_builder' ) ), number_format_i18n( get_comments_number() ) )
: ''
),
// adding tags:
(
( ( 'on' === $args['show_author'] || 'on' === $args['show_date'] || 'on' === $args['show_categories'] || 'on' === $args['show_comments'] ) && ( get_the_tag_list() && ! is_wp_error(get_the_tag_list()) ) )
? ' | '
: ''
),
(
( get_the_tag_list() && ! is_wp_error( get_the_tag_list() ) )
? '<span class="post-tags">' . get_the_tag_list( '', ', ' ) . '</span>'
: ''
)
);
/* Now paste this code in the place of the secondd match. Again, overwriting the original code: */
printf( '<p class="post-meta">%1$s %2$s %3$s %4$s %5$s %6$s %7$s %8$s %9$s</p>',
(
'on' === $show_author
? et_get_safe_localization( sprintf( __( 'by %s', 'et_builder' ), '<span class="author vcard">' . et_pb_get_the_author_posts_link() . '</span>' ) )
: ''
),
(
( 'on' === $show_author && 'on' === $show_date )
? ' | '
: ''
),
(
'on' === $show_date
? et_get_safe_localization( sprintf( __( '%s', 'et_builder' ), '<span class="published">' . esc_html( get_the_date( $meta_date ) ) . '</span>' ) )
: ''
),
(
(( 'on' === $show_author || 'on' === $show_date ) && 'on' === $show_categories)
? ' | '
: ''
),
(
'on' === $show_categories
? get_the_category_list(', ')
: ''
),
(
(( 'on' === $show_author || 'on' === $show_date || 'on' === $show_categories ) && 'on' === $show_comments)
? ' | '
: ''
),
(
'on' === $show_comments
? sprintf( esc_html( _nx( '%s Comment', '%s Comments', get_comments_number(), 'number of comments', 'et_builder' ) ), number_format_i18n( get_comments_number() ) )
: ''
),
// adding tags:
(
( ('on' === $show_author || 'on' === $show_date || 'on' === $show_categories || 'on' === $show_comments) && (get_the_tag_list() && ! is_wp_error(get_the_tag_list())) )
? ' | '
: ''
),
(
( get_the_tag_list() && ! is_wp_error( get_the_tag_list() ) )
? '<span class="post-tags">' . get_the_tag_list( '', ', ' ) . '</span>'
: ''
)
);
/* Add this code anywhere in child theme's functions.php. If you don't have a child theme add it to Divi's functions.php - but then it will be reset if you update Divi: */
/* adding tags to posts */
function et_pb_postinfo_meta( $postinfo, $date_format, $comment_zero, $comment_one, $comment_more ){
$postinfo_meta = '';
if ( in_array( 'author', $postinfo ) )
$postinfo_meta .= ' ' . esc_html__( 'by', 'et_builder' ) . ' <span class="author vcard">' . et_pb_get_the_author_posts_link() . '</span>';
if ( in_array( 'date', $postinfo ) ) {
if ( in_array( 'author', $postinfo ) ) $postinfo_meta .= ' | ';
$postinfo_meta .= '<span class="published">' . esc_html( get_the_time( wp_unslash( $date_format ) ) ) . '</span>';
}
if ( in_array( 'categories', $postinfo ) ) {
$categories_list = get_the_category_list(', ');
// do not output anything if no categories retrieved
if ( '' !== $categories_list ) {
if ( in_array( 'author', $postinfo ) || in_array( 'date', $postinfo ) ) $postinfo_meta .= ' | ';
$postinfo_meta .= $categories_list;
}
}
if ( in_array( 'comments', $postinfo ) ){
if ( in_array( 'author', $postinfo ) || in_array( 'date', $postinfo ) || in_array( 'categories', $postinfo ) ) $postinfo_meta .= ' | ';
$postinfo_meta .= et_pb_get_comments_popup_link( $comment_zero, $comment_one, $comment_more );
}
// adding tags:
$tag_list = get_the_tag_list( '', ', ' );
if ( $tag_list && ! is_wp_error( $tag_list ) ) {
if ( in_array( 'author', $postinfo ) || in_array( 'date', $postinfo ) || in_array( 'categories', $postinfo ) || in_array( 'comments', $postinfo ) ) $postinfo_meta .= ' | ';
$postinfo_meta .= '<span class="post-tags">' . $tag_list . '</span>';
}
return $postinfo_meta;
}
@TomOverthere
Copy link

No. I cannot make it work in the Blog Module.

@Geoplous
Copy link

Geoplous commented Sep 8, 2019

Hi, I made it work so maybe you want to use the code.
Check here: https://gist.github.com/Geoplous/2bc48b319f57ebfc58e1752d2ccdb9be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment