• Resolved eSabthok

    (@esabthok)


    Hi, my default language is working fine but in translated language when I visit home page, I can see full posts. I had inserted Read More tag on each posts. There should be Read More button after certain paragraphs.

Viewing 5 replies - 31 through 35 (of 35 total)
  • Plugin Author sbouey

    (@sbouey)

    Hi,

    i have update the other thread , i’m very sorry i make an error i send you the previous code and not the last one
    here is the full falang_translate_post_content you have to put in your funtion.php

    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;
    }
    Thread Starter eSabthok

    (@esabthok)

    With this code there is no php error but still read more button is not appearing. I cleared caches, cookies but it did not work.

    Just need to confirm: I put above code in function.php of my child theme and did not put any filter in falang plugin as you mentioned previously with new release no need to add filter in plugin we only have to add code in function.php.

    Please let me know the steps and code to fix this issue. I am using the Generatepress theme. I am losing my hope to fix this issue.

    Plugin Author sbouey

    (@sbouey)

    Hi, you don’t forget to add this after the function

    add_filter(‘falang_translate_post_content’,’falang_translate_post_content’);

    yes you have to add the code in the childtheme fucntion.php

    function falang_translate_post_content($content){
    ….
    ….
    }

    add_filter(‘falang_translate_post_content’,’falang_translate_post_content’);

    Thread Starter eSabthok

    (@esabthok)

    Hi have added add_filter(‘falang_translate_post_content’,’falang_translate_post_content’); but still I can not see the read more option, another user gave me code provide by you as per his reply and that code looks completely different on first half but I got php error for one line which is: ‘<span aria-label=”%1$s”>%2$s</span>’,

    He just paste it outside the code box so not sure if that was the actual code he wants to provide or not andd the code provided by him is this.

    //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’);
    Thread Starter eSabthok

    (@esabthok)

    Hi, Its fixed now. The correct code is as below in case needed in future for similar issue.

    //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');
    
Viewing 5 replies - 31 through 35 (of 35 total)
  • The topic ‘Read more option not appearing in translated posts’ is closed to new replies.