• Resolved jm17072011

    (@jm17072011)


    Hi,

    I don’t now why the “read more” link is not working anymore on my website.
    This is displayed instead:

    <br>Continue

    How can I fix it ?

    This is my functions.php :

    // Replaces the excerpt "Read More" text by a link
    function new_excerpt_more($more) {
           global $post;
    	return '<a class="moretag" href="'. get_permalink($post->ID) . '"><br>Continue</a>';
    }
    add_filter('excerpt_more', 'new_excerpt_more');

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi @jm17072011
    Please try below code in your functions.php file

    function new_excerpt_more($more) {
           global $post;
          return '<br><a class="moretag" href="'. get_permalink( $post->ID ) . '">' . __('Continue', 'your-text-domain') . '</a>';
    }
    add_filter('excerpt_more', 'new_excerpt_more');

    Hope this is useful for u ??

    Thread Starter jm17072011

    (@jm17072011)

    Hi,
    Thank you for your answer! I try it but it’s not working ??

    Hi @jm17072011

    You are getting the post by loop through. right ? so u can write the_excerpt() for getting excerpt of the posts and u can add <a></a> tag after the_excerpt().
    Add this code in the file where u write the loop for getting posts data.

    <?php the_excerpt(); ?>
    <br>
    <a class="moretag" href="<?php the_permalink() ?>">Continue</a>
    • This reply was modified 3 years, 1 month ago by Kajal Gohel.
    Thread Starter jm17072011

    (@jm17072011)

    I’m not sure to understand ! This is my theme that displays the link automatically when I create a block with multiple posts. It worked before. I didn’t touch the file and it stopped working all of a sudden. Instead of having the link I have this which is displayed on all my pages:
    <a class="moretag" href="https://parrainagedequalite.com/en/referral-blissim/"><br>Continue</a>

    (The link changes for each article but the rest is unchanged)

    • This reply was modified 3 years, 1 month ago by jm17072011.
    Thread Starter jm17072011

    (@jm17072011)

    I found this on my post-template.php file :

    function get_the_content( $more_link_text = null, $strip_teaser = false, $post = null ) {
    	global $page, $more, $preview, $pages, $multipage;
    
    	$_post = get_post( $post );
    
    	if ( ! ( $_post instanceof WP_Post ) ) {
    		return '';
    	}
    
    	// Use the globals if the $post parameter was not specified,
    	// but only after they have been set up in setup_postdata().
    	if ( null === $post && did_action( 'the_post' ) ) {
    		$elements = compact( 'page', 'more', 'preview', 'pages', 'multipage' );
    	} else {
    		$elements = generate_postdata( $_post );
    	}
    
    	if ( null === $more_link_text ) {
    		$more_link_text = sprintf(
    			'<span aria-label="%1$s">%2$s</span>',
    			sprintf(
    				/* translators: %s: Post title. */
    				__( 'Continue reading %s' ),
    				the_title_attribute(
    					array(
    						'echo' => false,
    						'post' => $_post,
    					)
    				)
    			),
    			__( '(more&hellip;)' )
    		);
    	}
    
    	$output     = '';
    	$has_teaser = false;
    
    	// If post password required and it doesn't match the cookie.
    	if ( post_password_required( $_post ) ) {
    		return get_the_password_form( $_post );
    	}
    
    	// If the requested page doesn't exist.
    	if ( $elements['page'] > count( $elements['pages'] ) ) {
    		// Give them the highest numbered page that DOES exist.
    		$elements['page'] = count( $elements['pages'] );
    	}
    
    	$page_no = $elements['page'];
    	$content = $elements['pages'][ $page_no - 1 ];
    	if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
    		if ( has_block( 'more', $content ) ) {
    			// Remove the core/more block delimiters. They will be left over after $content is split up.
    			$content = preg_replace( '/<!-- \/?wp:more(.*?) -->/', '', $content );
    		}
    
    		$content = explode( $matches[0], $content, 2 );
    
    		if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) {
    			$more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
    		}
    
    		$has_teaser = true;
    	} else {
    		$content = array( $content );
    	}
    
    	if ( false !== strpos( $_post->post_content, '<!--noteaser-->' ) && ( ! $elements['multipage'] || 1 == $elements['page'] ) ) {
    		$strip_teaser = true;
    	}
    
    	$teaser = $content[0];
    
    	if ( $elements['more'] && $strip_teaser && $has_teaser ) {
    		$teaser = '';
    	}
    
    	$output .= $teaser;
    
    	if ( count( $content ) > 1 ) {
    		if ( $elements['more'] ) {
    			$output .= '<span id="more-' . $_post->ID . '"></span>' . $content[1];
    		} else {
    			if ( ! empty( $more_link_text ) ) {
    
    				/**
    				 * Filters the Read More link text.
    				 *
    				 * @since 2.8.0
    				 *
    				 * @param string $more_link_element Read More link element.
    				 * @param string $more_link_text    Read More text.
    				 */
    				$output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink( $_post ) . "#more-{$_post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
    			}
    			$output = force_balance_tags( $output );
    		}
    	}
    
    	return $output;
    }
    
    /**
     * Display the post excerpt.
     *
     * @since 0.71
     */
    function the_excerpt() {
    
    	/**
    	 * Filters the displayed post excerpt.
    	 *
    	 * @since 0.71
    	 *
    	 * @see get_the_excerpt()
    	 *
    	 * @param string $post_excerpt The post excerpt.
    	 */
    	echo apply_filters( 'the_excerpt', get_the_excerpt() );
    }
    
    /**
     * Retrieves the post excerpt.
     *
     * @since 0.71
     * @since 4.5.0 Introduced the <code>$post</code> parameter.
     *
     * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
     * @return string Post excerpt.
     */
    function get_the_excerpt( $post = null ) {
    	if ( is_bool( $post ) ) {
    		_deprecated_argument( __FUNCTION__, '2.3.0' );
    	}
    
    	$post = get_post( $post );
    	if ( empty( $post ) ) {
    		return '';
    	}
    
    	if ( post_password_required( $post ) ) {
    		return __( 'There is no excerpt because this is a protected post.' );
    	}
    
    	/**
    	 * Filters the retrieved post excerpt.
    	 *
    	 * @since 1.2.0
    	 * @since 4.5.0 Introduced the <code>$post</code> parameter.
    	 *
    	 * @param string  $post_excerpt The post excerpt.
    	 * @param WP_Post $post         Post object.
    	 */
    	return apply_filters( 'get_the_excerpt', $post->post_excerpt, $post );
    }
    Thread Starter jm17072011

    (@jm17072011)

    I resolve this issue ! I don’t know why but this is the Gutenberg extension which is the problem ! I deactivated it and it works

    • This reply was modified 3 years, 1 month ago by jm17072011.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘“read more” link not working’ is closed to new replies.