Forum Replies Created

Viewing 15 replies - 1 through 15 (of 58 total)
  • Thread Starter fabykennedy

    (@fabykennedy)

    I’m glad to help!

    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');
    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’);

    Thread Starter fabykennedy

    (@fabykennedy)

    Never mind, I’ve found a solution. It may be artisanal but it’s better than nothing… Whoever in need can take a look at it here.

    What I don’t understand is that I’m not the only one having this problem… Maybe a theme related issue?

    fabykennedy

    (@fabykennedy)

    I think I’ve found a solution. Well, it’s quite “artisanal” but effective.

    I state that I’m using another plugin instead of Yoast Duplicate Post but it should do the trick as well.

    When you rewrite and republish a post the translated one loses the linking with it right? Well, all you have to do is republish the article that loses the linking. No matter if you don’t apply any edits, just use the plugin to republish it. After that, you’ll be able to link it again to the other one. Try writing the post title in the autocomplete input field, this time Polylang will recognize the article and you’ll be able to add it as a translation.

    I’m still testing this solution in my local environment but so far so good. Hope it helps.

    fabykennedy

    (@fabykennedy)

    All right, my mistake, I did a copy and paste of the title instead of writing it manually. But once again there’s a problem… I write the title, see the dropdown menu with all possible articles where to choose from and it finds anything but the one I need… It’s absurd… It’s like the articles I rewrite and republish no longer existed for Polylang… Didn’t you encounter the same issue? Anyway I reported it on the support forum but I’m almost sure they won’t reply me…

    fabykennedy

    (@fabykennedy)

    Yes I tried but it didn’t work. So are you telling me that it’s only about writing the title of the existing article in the field?

    In case your answer is positive I’ll be forced to contact the assistance because it would mean there’s definitely something wrong here.

    fabykennedy

    (@fabykennedy)

    First of all, thank you very much for your infinite patience.

    The point is… how can I link the articles again through Polylang? Let’s make an example.

    I rewrite and republish a native post, Italian in my case. Automatically, the translated one in English loses its link with it. Now, if I open that article I’ll obviously notice that the Italian translation is missing as a consequence of the linking break. So, how can I link it again with the Italian one? Of course I can’t add a new translation by pressing on the + button… It would mean writing a new article, but obviously I have it already, it’s just that it’s missed the linking!

    Image here

    Sorry for the long post but I wouldn’t have known how to explain it without a practical example.

    fabykennedy

    (@fabykennedy)

    Ok but… Do you mean manually intervene in the html code to edit the <head> section? If so, how can I do that?

    fabykennedy

    (@fabykennedy)

    Hi and thank you very much for your reply.

    Yet, I haven’t understood your fix. Could you kindly explain it further? Thanks.

    fabykennedy

    (@fabykennedy)

    Any fix for this?

    Thread Starter fabykennedy

    (@fabykennedy)

    Some help please?

    Thread Starter fabykennedy

    (@fabykennedy)

    Hi there and thanks for replying. I did as you said but unfortunately I’ve still got the issue. In my case I have an Italian blog with English translations.

    When I edit a native post it holds the link with the translated one, but conversly the English post looses the hreflang tag. Eventually, when even the translated article is edited and republished, they both loose the link.

    Anyway this is happening with every plugin of this kind I’m testing in my local environment.

    Same here… Any news?

    Thread Starter fabykennedy

    (@fabykennedy)

    Hi and thank you for replying.

    Is the first code (Exclude specific posts) meant for setting “no index”? If yes, how should I use it to set the tag to the desired posts? Moreover, should I put the code in the function.php file?

    Thanks.

Viewing 15 replies - 1 through 15 (of 58 total)