Excerpts blog section
-
Dear Webhunt,
I am currently tweeking my blogsection on the homepage
http://einstein-empowerment.academy/I would like the excerpts to al have the same length. So the boxes show a linaer row.
Is there a way to change the excerpt from 165 words to for example 310 signs including spaces?
I allready tried working with the ‘read more’ tag in the blog but that doesn’t pick up of makes the read more option go away in the excerpt on the homepage (as you can see http://einstein-empowerment.academy/)
Thanks in advance and kind regards, Julia
-
You can try adding this in your themes
functions.phpfile:
apply_filters( 'excerpt_length', 60 ), 60 is the number of words you want to display.Hope this will help you!
Hi,
@subrataemfluence thank you for your help.
Please create “Child-Theme” first and perform all the changes using “Child-Theme”.
Let us know for further assistance.
Thank You
Hi there,
Thanks for the quick response.The child theme is allready active, so I can work with that.
But,
The amount of words is not the problem. Because 60 words still give diferent lengths in the boxes. At the moment the length is 165 words, which is fine.
But I would like to change it to counting the signs/letters including spaces.For example my first three posts are all 165 words long, but 344, 319 and 384 signs which makes the boxes different. It looks ugly if you ask me.
Do you have a hint for this change, Webhunt of Subrata?
Kind regards,
Hi,
Create a “functions.php” file into your “Child-Theme” directory and open it.
Now paste below line of code snippet:
function get_excerpt($limit, $source = null){ if($source == "content" ? ($excerpt = get_the_content()) : ($excerpt = get_the_excerpt())); $excerpt = preg_replace(" (\[.*?\])",'',$excerpt); $excerpt = strip_shortcodes($excerpt); $excerpt = strip_tags($excerpt); $excerpt = substr($excerpt, 0, $limit); $excerpt = substr($excerpt, 0, strripos($excerpt, " ")); $excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt)); return $excerpt; }After it copy “home-blog.php” from your parent theme directory and paste into your “Child-Theme” directory.
Open it into any text editor.
Now find below line of code snippet.
<?php if(is_page() || is_singular()) { the_content(); } else { the_excerpt(); } ?>and replace with this
<?php if(is_page() || is_singular()) { the_content(); } else { echo get_excerpt(300); } ?>Save all the changes.
Hope it will work for you.
Note: you can change get_excerpt(300) according your need.
Thank you
It worked!
Thanks for coding this part!!
Kind regards, JuliaDo you have any idea what happened tot the read more tags?
Hi,
Sorry for delay in response.
Please use below line of code instead of above:
function get_excerpt($limit, $source = null){ global $post; if($source == "content" ? ($excerpt = get_the_content()) : ($excerpt = get_the_excerpt())); $excerpt = preg_replace(" (\[.*?\])",'',$excerpt); $excerpt = strip_shortcodes($excerpt); $excerpt = strip_tags($excerpt); $excerpt = substr($excerpt, 0, $limit); $excerpt = substr($excerpt, 0, strripos($excerpt, " ")); $excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt)); if($limit>=300){ $excerpt = $excerpt.'<a href="' . get_permalink() . '" class="readmore">' . __('Read More...', 'awada') . '</a>'; } return $excerpt; }Save the changes.
Let us know for further assistance.
Thank You
Thank you for your extra coding.
I have a problem with the theme now. When I activated the new function.php the site became unreacheble and without the functions.php it was a mess.
I had to place the original theme back, since I am going on holiday tomorrowmorning.
Do you have any idea if the multiple functions are interfering the child theme to work correctly of did I interupt something somewhere else?
—
<?php
add_action( ‘wp_enqueue_scripts’, ‘child_enqueue_styles’,99);
function child_enqueue_styles() {
$parent_style = ‘parent-style’;
wp_enqueue_style( $parent_style, get_template_directory_uri() . ‘/style.css’ );
wp_enqueue_style( ‘child-style’,get_stylesheet_directory_uri() . ‘/custom.css’, array( $parent_style ));
}
if ( get_stylesheet() !== get_template() ) {
add_filter( ‘pre_update_option_theme_mods_’ . get_stylesheet(), function ( $value, $old_value ) {
update_option( ‘theme_mods_’ . get_template(), $value );
return $old_value; // prevent update to child theme mods
}, 10, 2 );
add_filter( ‘pre_option_theme_mods_’ . get_stylesheet(), function ( $default ) {
return get_option( ‘theme_mods_’ . get_template(), $default );
} );
}
add_action( ‘pre_get_posts’, ‘tribe_post_date_ordering’, 51 );
function tribe_post_date_ordering( $query ) {
if ( $query->tribe_is_multi_posttype) {
remove_filter( ‘posts_fields’, array( ‘TribeEventsQuery’, ‘multi_type_posts_fields’ ) );
$query->set( ‘order’, ‘DESC’ );
}
function get_excerpt($limit, $source = null){
global $post;
if($source == “content” ? ($excerpt = get_the_content()) : ($excerpt = get_the_excerpt()));
$excerpt = preg_replace(” (\[.*?\])”,”,$excerpt);
$excerpt = strip_shortcodes($excerpt);
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, $limit);
$excerpt = substr($excerpt, 0, strripos($excerpt, ” “));
$excerpt = trim(preg_replace( ‘/\s+/’, ‘ ‘, $excerpt));
if($limit>=300){
$excerpt = $excerpt.’‘ . __(‘Read More…’, ‘awada’) . ‘‘;
}
return $excerpt;
}
?>—
Kind regards, Julia
(My reply may take some time. Back home after 18th of June)<?php add_action( 'wp_enqueue_scripts', 'child_enqueue_styles',99); function child_enqueue_styles() { $parent_style = 'parent-style'; wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' ); wp_enqueue_style( 'child-style',get_stylesheet_directory_uri() . '/custom.css', array( $parent_style )); } if ( get_stylesheet() !== get_template() ) { add_filter( 'pre_update_option_theme_mods_' . get_stylesheet(), function ( $value, $old_value ) { update_option( 'theme_mods_' . get_template(), $value ); return $old_value; // prevent update to child theme mods }, 10, 2 ); add_filter( 'pre_option_theme_mods_' . get_stylesheet(), function ( $default ) { return get_option( 'theme_mods_' . get_template(), $default ); } ); } add_action( 'pre_get_posts', 'tribe_post_date_ordering', 51 ); function tribe_post_date_ordering( $query ) { if ( $query->tribe_is_multi_posttype) { remove_filter( 'posts_fields', array( 'TribeEventsQuery', 'multi_type_posts_fields' ) ); $query->set( 'order', 'DESC' ); } function get_excerpt($limit, $source = null){ global $post; if($source == "content" ? ($excerpt = get_the_content()) : ($excerpt = get_the_excerpt())); $excerpt = preg_replace(" (\[.*?\])",'',$excerpt); $excerpt = strip_shortcodes($excerpt); $excerpt = strip_tags($excerpt); $excerpt = substr($excerpt, 0, $limit); $excerpt = substr($excerpt, 0, strripos($excerpt, " ")); $excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt)); if($limit>=300){ $excerpt = $excerpt.'<a href="' . get_permalink() . '" class="readmore">' . __('Read More...', 'awada') . '</a>'; } return $excerpt; } ?>Hi @webhuntsupport,
I want to provide you my package, but how should I deliver?
Is there a way to upload .php documents or should you have online access?Kind regards,
The topic ‘Excerpts blog section’ is closed to new replies.
