Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1477768

    i have on one installation this snippet to decide even on alb generated posts/portfolio to show the featured image:

    function avf_template_builder_content_postimage_mod($content = ""){
      if(  (is_singular('post') || is_singular('portfolio')) && ( '1' != get_post_meta( get_the_ID(), '_avia_hide_featured_image', true ) ) )  {
            $featuredImage = get_the_post_thumbnail( $the_id, 'original' );
            $content = '<header class="entry-content-header"><div class="page-thumb">' .$featuredImage. '</div></header>' . $content ;
          }
      return $content;
    }
    add_filter('avf_template_builder_content', 'avf_template_builder_content_postimage_mod', 10, 1);

    now the site turned to show a page es footer !
    we now got $content twice !
    so the featured image is inserted to post content and to footer content. How to avoid that
    (Yes i know i can set it via css to display none – but that is (double content) a bad solution)

    #1477800

    Hey Guenter,

    What about using a static var in the handler at the beginning like:

    
    
    static $exec = false;  //  initialise
    
    if( $exec )
    {
    return $content ;
    }
    
    $exec = true;     //  set flag as executed
    .....
    
    
    

    Best regards,
    Günter

    #1477896

    can you please post the full code – i do not see how to combine both if clauses.

    because my solution removes the curtain footer from the footer page when i like to show the featured image.

    #1477902

    Hi,

    If I understand you correctly the featured image is displayed also in the footer and you do not want to have it there.

    My snippet avoids to display it a second time.
    Simply add it at the beginning of the function:

    
    function avf_template_builder_content_postimage_mod($content = ""){
    
    static $exec = false;  //  initialise
    
    if( $exec )   // check if function was already executed once
    {
    return $content ;
    }
    
    $exec = true;     //  set flag as executed
    
    if(  (is_singular('post') || is_singular('portfolio')) && ( '1' != get_post_meta( get_the_ID(), '_avia_hide_featured_image', true ) ) )  {
    
    ......
    
    
    
    
    

    Best regards,
    Günter

    #1477905

    ist jetzt nicht so eilig. Ich schaue mal ob ich es anders hinbekomme.
    Deine Reihenfolge entfernt mir den main content – meine Reihenfolge die Footer Page.

    #1477912

    Hi,

    Ich habe den Code in Deine child functions.php unten eingefügt.

    Ohne static erscheint bild im footer, mit nicht mehr.
    Link siehe unten.

    Best regards,
    Günter

    #1477961

    hm – ich dachte es so gemacht zu haben. Egal – jetzt geht es. Vielen Dank !

    #1478001

    Hi,

    Gerne.
    Einen schönen Tag noch.

    LG,
    Günter

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘how to avoid insertion to content twice …’ is closed to new replies.