Home Forums Weaver Xtreme Theme Image caption in Excerpt

Topic Resolution: Resolved
Viewing 16 posts - 1 through 16 (of 18 total)
  • Author
    Posts
  • #56218
    MMWBAdmin
    Participant

    Hi,

    not sure whether this is caused by Gutenberg, WVRX or the combination. Wrote a post that starts with an Image Block, followed by paragraphs. This post is shown as an excerpt in a Weaver Slider on the homepage. Now the excerpt starts with the Image Caption (= Hyperinflatie Venezuela). Can’t remember this ever happening before. WP 4.9.8, Gut 3.7.0, WVRX Theme 4.0.5, most recent Weaver Plugins, PHP 7.2

    For now I leave the Image Caption in place.

     

    #56220
    scrambler
    Moderator

    In the site, the caption text is physically part of the post content, so if this is not how the content is made, I would suspect an issue with Guttenberg, because weaver does not touch the content.

    #59905
    MMWBAdmin
    Participant

    WordfENCE

    #59906
    MMWBAdmin
    Participant

    On submitting a reply I get:
    <h2>403 Forbidden</h2>
    A potentially unsafe operation has been detected in your request to this site.

    <hr />

    Generated by Wordfence at Tue, 18 Jun 2019 14:44:30 GMT.
    Your computer’s time: Tue, 18 Jun 2019 14:44:30 GMT.

    #59907
    MMWBAdmin
    Participant

    Reply (part 1)

    This issue is raised with Gutenberg. Otto 42 writes (Sep 2018):

    “This is because wp_trim_excerpt() in core does not know about Gutenberg yet.
    In WordPress 4.9, the editor creates images by using the caption shortcode. Content it creates will look like this (shortened for brevity):
    Caption here
    In Gutenberg, images created by the image or gallery blocks look like this:
    <figure class= … ><figcaption>Caption here</figcaption></figure>
    The wp_trim_excerpt function in core generates the automatic excerpt from content. It calls the strip_shortcodes() function on that content at one point. The old way has shortcodes for captions, the new way does not.” (Bold by me)

     

    #59908
    MMWBAdmin
    Participant

    Reply (part 2)

    Weaverx contains a function weaverx_trim_excerpt( $text = ” ) in lib-content.php (around line 1160 – 1165). This function contains”
     $text = strip_shortcodes( $text );

    Might this have something to do with my issue?
    Kind regards,
    Wyb Anema

    PS. Issue not visible in my site (mmwb.nl) anymore as I wrote a function that removes the caption from the excerpt. If needed I can of course disable this function on your request to see what happens and what the issue looks like.

    #59909
    scrambler
    Moderator

    @weaver will have to comment when he is back

    #59913
    Weaver
    Keymaster

    This is indeed an issue with the Block Editor, and there does not seem to be any fix for it at this point. Quite annoying!

    I will follow this issue to see if some resolution is announced.

    What code did you used to remove the caption?

    #59922
    MMWBAdmin
    Participant

    As you say. Quite annoying.

    I added some lines of code to lib-content.php in function weaverx_the_post_excerpt() (on line 941):

    weaverx_fi( ‘post_excerpt’, ‘content-top’ );

    $vip_post = get_the_ID();

    $wvip_excerpt = get_the_excerpt();

    echo excerpt_no_caption ( $vip_excerpt , $vip_post);

    //       the_excerpt( ‘more…’ );

    weaverx_fi( ‘post_excerpt’, ‘content-bottom’ );

    And added the function:

    function excerpt_no_caption ($vip_excerpt, $vip_post) {
    $vip_leeg = “”;
    $vip_attach =
       array(
    ‘post_parent’ => $vip_post,
    ‘post_type’ => ‘attachment’,
    ‘post_mime_type’ => ‘image’,
    ‘posts_per_page’ => 1,
    ‘order’=> ‘ASC’);

       $vip_children = get_children($vip_attach);
    if ($vip_children) {
    foreach ($vip_children as $attachment_id=> $attachment)  {
             $test_caption = wp_get_attachment_caption ($attachment_id);
             if ($test_caption <> ‘x’) {
    $vip_excerpt = str_replace($test_caption, $vip_leeg , $vip_excerpt);
    }
         }
    $vip_attach = 0;
    }
    return $vip_excerpt;
    }

     

    #59975
    MMWBAdmin
    Participant

    <h2>403 Forbidden</h2>
    A potentially unsafe operation has been detected in your request to this site.

    #59976
    MMWBAdmin
    Participant

    Can’t submit reply

    #59978
    scrambler
    Moderator

    Posting code often gets flagged by the WordPress security plugin.

    make sure you select all the code and give it the “Preformatted” Paragraph style

    #59980
    MMWBAdmin
    Participant
    function excerpt_no_caption ($wyb_post_id) {
    	$wyb_leeg = "";
    	$wyb_excerpt = get_the_excerpt(); 
    	$vip_post = get_post( $wyb_post_id );
    	$vip_content = substr(apply_filters( 'the_content', $vip_post->post_content ),0,700);
    	preg_match('(<figc\w+>(?:[ [email protected]),(#&+-]*)<\/\w+tion>)', $vip_content, $vip_match);
    	$test_caption = strip_tags($vip_match[0]);
    	if ($test_caption <> $wyb_leeg) {
    		$wyb_excerpt = str_replace($test_caption, $wyb_leeg , $wyb_excerpt);		
    		}  
    	return $wyb_excerpt;
    }
    #59981
    MMWBAdmin
    Participant

    To find the image-caption in the specific post – instead of the caption of the image – replaced code by: see previous post

    #63048
    MMWBAdmin
    Participant

    Hi again,

    this issue – image caption in excerpt – should be solved in WP 5.0, as explained by Will Skora on Github / WP / Gutenberg yesterday & today

    In short he advised me to contact you (again) because

    “The weaver theme removes the filter of wp_trim_excerpt (line 1171 of includes/lib-content.php) and instead uses a custom function that does not filter out any blocks’ content; (line 1145).”

    Hope this can help to solve this issue.

    Kind regards

    #63050
    scrambler
    Moderator

    @weaver will have to comment

Viewing 16 posts - 1 through 16 (of 18 total)
  • You must be logged in to reply to this topic.