• Resolved fabykennedy

    (@fabykennedy)


    Hi. I’m sorry to post a topic after another but I’ve got a very bad problem. Full posts were displayed in the homepage instead of showing just a paragraph with the “continue reading” button.

    There was a user with my exact issue and he was told to add a code in the functions.php file. I did it and it basically worked but… Posts are now showing without the “continue reading” button. But the biggest problem is that every time I open an article to fully read it, I can see only a paragraph. The rest of the content is lost.

    Please let me know hot to solve the problem. Thank you.

Viewing 9 replies - 16 through 24 (of 24 total)
  • Hi Fabykennedy, I am still having this issue and saw that the code provided by the team is working for your site. Could you please me the full code you inserted in your function.php?

    This is the code provided to me and it does not show any read more button instead shows full posts.

    Thanks in advance.

    function falang_translate_post_content($content){
        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 );
            }
    
            $_post = get_post();
    
            $output     = '';
    
            $content = explode( $matches[0], $content, 2 );
    
            if ( ! empty( $matches[1] ) ) {
                $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
            }
    
            $output = $content[0];
    
            if ( count( $content ) > 1 ) {
                if ( ! empty( $more_link_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;
    
        }
        return $content;
    }
    
    Thread Starter fabykennedy

    (@fabykennedy)

    Hi, here’s the code I’ve been sent and that worked for me.

    //see wp-includes/post-template.php
    //function falang_translate_post_content_old($content){
    // 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 );
    // }
    //
    // $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…)’ )
    // );
    //
    //
    // $output = ”;
    //
    // $content = explode( $matches[0], $content, 2 );
    //
    // if ( ! empty( $matches[1] ) ) {
    // $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
    // }
    //
    // $output = $content[0];
    //
    // if ( count( $content ) > 1 ) {
    // if ( ! empty( $more_link_text ) ) {
    // $output .= apply_filters( ‘the_content_more_link’, ‘ ID}\” class=\”more-link\”>$more_link_text“, $more_link_text );
    // }
    // }
    // $output = force_balance_tags( $output );
    // return $output;
    //
    // }
    // return $content;
    //}

    function falang_translate_post_content($content){
    global $page, $more, $preview, $pages, $multipage;

    global $post;
    $more_link_text = null;

    $_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…)’ )
    );
    }

    $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’, ‘ ID}\” class=\”more-link\”>$more_link_text“, $more_link_text );
    }
    $output = force_balance_tags( $output );
    }
    }

    return $output;
    }

    add_filter(‘falang_translate_post_content’,’falang_translate_post_content’);

    Plugin Author sbouey

    (@sbouey)

    Hi,
    i’m very sorry , i make an error the full code is this one

    
    function falang_translate_post_content($content){
        global $page, $more, $preview, $pages, $multipage;
    
        global $post;
        $more_link_text = null;
    
        $_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;
    }

    Thank you both for providing the code but none of them work for me. There is no error in Code provided by Sbouey but still read more button is not appering.

    And code provided by @fabykennedy is showing php error. Could you please provide me the exact code using CODE tag.

    I am confused how come codes provided by both of you are different for the same purpose, there should be one correct code to fix specific issues. I am hopeless now.

    Plugin Author sbouey

    (@sbouey)

    i have put my response in the other thread

    sorry to disturb you @fabykennedy , with the code provided by you I am getting PHP error again. It shows an error for one line which I have pasted below in bold.

    ‘<span aria-label=”%1$s”>%2$s</span>’,

    Could you please paste the exact code into the code box?

    Thread Starter fabykennedy

    (@fabykennedy)

    Hi, no problem!

    I actually tried to use the CODE block but it didn’t work for some reason… I’m gonna try again. Here’s the code that worked for me:

    //see wp-includes/post-template.php
    //function falang_translate_post_content_old($content){
    //    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 );
    //        }
    //
    //        $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     = '';
    //
    //        $content = explode( $matches[0], $content, 2 );
    //
    //        if ( ! empty( $matches[1] ) ) {
    //            $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
    //        }
    //
    //        $output = $content[0];
    //
    //        if ( count( $content ) > 1 ) {
    //            if ( ! empty( $more_link_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;
    //
    //    }
    //    return $content;
    //}
    
    function falang_translate_post_content($content){
        global $page, $more, $preview, $pages, $multipage;
    
        global $post;
        $more_link_text = null;
    
        $_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;
    }
    
    add_filter('falang_translate_post_content','falang_translate_post_content');

    Thank you very much. Finally solved this problem. Thank you

    Thread Starter fabykennedy

    (@fabykennedy)

    I’m glad to help!

Viewing 9 replies - 16 through 24 (of 24 total)
  • The topic ‘Missing continue reading button’ is closed to new replies.