
-
AuthorPosts
-
February 24, 2025 at 11:34 am #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)February 24, 2025 at 5:20 pm #1477800Hey 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ünterFebruary 25, 2025 at 1:17 pm #1477896can 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.
February 25, 2025 at 2:01 pm #1477902Hi,
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ünterFebruary 25, 2025 at 2:56 pm #1477905ist jetzt nicht so eilig. Ich schaue mal ob ich es anders hinbekomme.
Deine Reihenfolge entfernt mir den main content – meine Reihenfolge die Footer Page.February 25, 2025 at 4:29 pm #1477912Hi,
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ünterFebruary 25, 2025 at 11:39 pm #1477961hm – ich dachte es so gemacht zu haben. Egal – jetzt geht es. Vielen Dank !
February 26, 2025 at 9:01 am #1478001 -
AuthorPosts
- The topic ‘how to avoid insertion to content twice …’ is closed to new replies.