0

Excerpt functions is removing the forward slash on the url - I am completely lost here I can't find a way to make it work.

I am very new on php programming any help would be very appreciated.

I am calling this function on my index.php

index.php :

<?php echo get_excerpt_max_charlength('260', true) ?>   



functions.php :


function get_excerpt_max_charlength($charlength, $readmore = true) {
$excerpt = get_the_excerpt();
$charlength++;

if ( mb_strlen( $excerpt ) > $charlength ) {
    $subex = mb_substr( $excerpt, 0, $charlength - 5 );
    $exwords = explode( ' ', $subex );
    $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
    if ( $excut < 0 ) {
        $str = mb_substr( $subex, 0, $excut );
    } else {
        $str = $subex;
    }
    return $readmore ? $str . '&hellip; <a href="' . get_permalink() . '">' . __('read more') . '</a>' : $str . '&hellip;';
} else {
    return $excerpt;
}
} 

Forward slash removed :

enter image description here

UPDATE I have found the fix - not bad for someone is new in programming.

 return $readmore ? $str . '<a class="more-link" href="'. get_permalink($post->ID) . '">'. __('read more') .'</a>' . '</a>' : $str . '&hellip;';
7
  • While you are new to programming, I would advice you to refrain from bad coding practices. First of all, never ever use those crappy php shortags (<?=) you are using. It is not recommended for use, use proper php tags (<?php and ?>). Also, properly indend your code to make is easier to read. Sloppy code hides bugs Apr 6, 2016 at 12:19
  • @PieterGoosen well I have to disagree regarding the short_open_tag - they are fine IF defined on php.ini. Regarding the indend Subline does the work for me, sorry for copying and past it. Apr 6, 2016 at 12:36
  • @PieterGoosen I wonder why you have voted negative in my question Apr 6, 2016 at 12:47
  • @PieterGoosen <?= is absolutely fine for templates. These are not the regular short open tags.
    – fuxia
    Apr 6, 2016 at 12:48
  • @NunoS please post your update as an answer. Please note, if you have issues with how people vote, please raise an issue on WordPress Development Meta, the main stack is not meant to discuss off topic issues Apr 6, 2016 at 15:59

1 Answer 1

0

Here is the fix:

 return $readmore ? $str . '<a class="more-link" href="'. get_permalink($post->ID) . '">'. __('read more') .'</a>' . '</a>' : $str . '&hellip;';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.