Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1485733

    Greetings, I’m wanting to change the “Read More” text (on the link button) for select blog categories. Using the support forum I have tried adding the following code to my child theme functions.php file:

    Begin Code:

    function avf_modify_standard_post_content( $current_post ) {
    if ( $current_post[‘post_format’] === ‘standard’ ) {
    $categories = get_the_category( $current_post[‘ID’] );
    $category_names = wp_list_pluck( $categories, ‘name’ );

    if ( in_array( ‘Dharma Talks’, $category_names ) ) {
    $read_more_text = __( ‘Listen/Read More’, ‘avia_framework’ );
    } elseif ( in_array( ‘Music Recordings’, $category_names ) ) {
    $read_more_text = __( ‘Listen to this’, ‘avia_framework’ );
    } else {
    $read_more_text = __( ‘Read more’, ‘avia_framework’ );
    }

    $current_post[‘content’] = $current_post[‘content’] .
    ‘<div class=”read-more-link”>‘ .
    $read_more_text .
    ‘<span class=”more-link-arrow”></span>
    </div>’;
    }

    return $current_post;
    }
    add_filter( ‘post-format-standard’, ‘avf_modify_standard_post_content’ );
    End Code
    This actually works, however, the result is on each blog post I now have two button links: the first is the original Read more and the second is one of the above. So two button links. How can I get this to function correctly.

    • This topic was modified 3 weeks, 2 days ago by ajaxkls.
    #1485759

    Hey ajaxkls,
    Could you add a admin login so we can examine, your snippet above is not in a “code” clip so we can’t examine it fully and our test site doesn’t have the same categories so it is hard to reproduce.

    Best regards,
    Mike

    #1485762
    This reply has been marked as private.
    #1485779

    Can you help please?

    #1485781

    Hi,

    Thank you for the info.

    You may need to manually remove this line from the includes/loop-index.php file, around line 151.

    $current_post['content'] = $blog_content == 'content' ? get_the_content( __( 'Read more', 'avia_framework' ) . $more_link_arrow ) : get_the_excerpt();
    			$current_post['content'] = $blog_content == 'excerpt_read_more' ? $current_post['content'] . '
    <div class="read-more-link"><a href="' . get_permalink() . '" class="more-link">' . __( 'Read more', 'avia_framework' ) . $more_link_arrow . '</a></div>
    ' : $current_post['content'];
    			$current_post['before_content'] = '';
    

    To override the template, you can create a copy of /includes/loop-index.php in your child theme folder.

    Another option is to edit the filter and ensure that the $current_post[‘content’] is blank before appending the new read more link.

    $current_post['content'] = "";
    

    Best regards,
    Ismael

    #1485806

    Thank you. I copied the entire /includes/ folder to the child theme and removed the line from the includes/loop-index.php file. It caused the entire blog not to load.

    On the another option can you tell me exactly where to edit the filter and add the line: $current_post[‘content’] = “”; Is it in the functions.php file?

    Kurt

    #1485822

    Hi,

    On the another option can you tell me exactly where to edit the filter and add the line: $current_post[‘content’] = “”;

    Try to replace the whole post-format-standard filter with this:

    function avf_modify_standard_post_content( $current_post ) {
        if ( $current_post['post_format'] === 'standard' ) {
            global $avia_config;
    
            $blog_content = ! empty( $avia_config['blog_content'] ) ? $avia_config['blog_content'] : 'content';
            $more_link_arrow = '<span class="more-link-arrow"></span>';
    
            $categories = get_the_category( $current_post['ID'] );
            $category_names = wp_list_pluck( $categories, 'name' );
    
            if ( in_array( 'Dharma Talks', $category_names ) ) {
                $read_more_text = __( 'Listen/Read More', 'avia_framework' );
            } elseif ( in_array( 'Music Recordings', $category_names ) ) {
                $read_more_text = __( 'Listen to this', 'avia_framework' );
            } else {
                $read_more_text = __( 'Read more', 'avia_framework' );
            }
    
            $current_post['before_content'] = '';
    
            if ( $blog_content == 'content' ) {
                $current_post['content'] = get_the_content( $read_more_text . $more_link_arrow );
            } else {
                $current_post['content'] = get_the_excerpt();
            }
    
            if ( $blog_content === 'excerpt_read_more' ) {
                $current_post['content'] .= '
    <div class="read-more-link"><a href="' . get_permalink() . '" class="more-link">' . esc_html( $read_more_text ) . $more_link_arrow . '</a></div>
    ';
            }
        }
    
        return $current_post;
    }
    add_filter( 'post-format-standard', 'avf_modify_standard_post_content' );
    

    This block resets the post content to blank, then re-adds the post content or excerpt.

    $current_post['before_content'] = '';
    
            if ( $blog_content == 'content' ) {
                $current_post['content'] = get_the_content( $read_more_text . $more_link_arrow );
            } else {
                $current_post['content'] = get_the_excerpt();
            }
    

    Best regards,
    Ismael

    #1485863

    Excellent, thanks for your help.

    #1485869

    Hi,

    Glad we could be of help! Feel free to reach out if you have more questions. Have a nice day.

    Best regards,
    Ismael

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘Blog Element Excerpt Read More Text Duplication …’ is closed to new replies.