Hello Bravokeyl,
I don’t why these posted solutions rarely work for me. ?? I added your code to functions.php in my childtheme… but the excerpts keep on showing […] without a link (and without any error message…)
Here is my functions.php:
<?php
if ( function_exists('register_sidebar') ) {
register_sidebar( array(
'name' => __( 'First Footer Widget Area', 'twentyfourteen' ),
'id' => 'sidebar-4',
'description' => __( 'First footer widget area', 'twentyfourteen' ),
'before_widget' => '<div class="textwidget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
// Area 6, located in the footer. Empty by default.
register_sidebar( array(
'name' => __( 'Second Footer Widget Area', 'twentyfourteen' ),
'id' => 'sidebar-5',
'description' => __( 'Second footer widget area', 'twentyfourteen' ),
'before_widget' => '<div class="textwidget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
// Area 7, located in the footer. Empty by default.
register_sidebar( array(
'name' => __( 'Third Footer Widget Area', 'twentyfourteen' ),
'id' => 'sidebar-6',
'description' => __( 'The third footer widget area', 'twentyfourteen' ),
'before_widget' => '<div class="textwidget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
// Area 8, located in the footer. Empty by default.
register_sidebar( array(
'name' => __( 'Fourth Footer Widget Area', 'twentyfourteen' ),
'id' => 'sidebar-7',
'description' => __( 'The fourth footer widget area', 'twentyfourteen' ),
'before_widget' => '<div class="textwidget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
/** Génèse des ancres
*/
function replace_ca($matches){
return '<h'.$matches[1].$matches[2].' id="'.sanitize_title($matches[3]).'">'.$matches[3].'</h'.$matches[4].'>';
}
//Ajout d'un filtre sur le contenu
add_filter('the_content', 'add_anchor_to_title', 12);
function add_anchor_to_title($content){
if(is_singular('post')){ // s'il s'agit d'un article
global $post;
$pattern = "/<h([2-4])(.*?)>(.*?)<\/h([2-4])>/i";
$content = preg_replace_callback($pattern, 'replace_ca', $content);
return $content;
}else{
return $content;
}
}
/** Function automenu( $echo = false )
*/
function automenu(){
global $post;
$obj = '<nav class="sommaire-article"><ul>';
$original_content = $post->post_content;
//on récupère les titres
$patt = "/<h([2-4])(.*?)>(.*?)<\/h([2-4])>/i";
preg_match_all($patt, $original_content, $results);
//on génère les liens
foreach ($results[3] as $k=> $r) {
$obj .= '<li><a href="#'.sanitize_title($r).'" class="title_lvl'.$results[1][$k].'">'.$niveau.$r.'</a></li>';
}
$obj .= '</nav>';
if ( $echo )
echo $obj;
else
return $obj;
}
// shortcode
add_shortcode('sommaire','automenu');
//template
automenu( true );
/** Function liens sur lire plus
function child_excerpt_more( $more ) {
return ' <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">Read more</a>';
}
add_filter( 'excerpt_more', 'child_excerpt_more' );
Do you have any idea?
Hopefully,
Tche’ers