- This topic has 51 replies, 5 voices, and was last updated 1 year, 4 months ago by David.
-
AuthorPosts
-
November 23, 2022 at 2:35 am #2428638DavidStaffCustomer Support
Can you try using this snippet instead ?
add_shortcode('portable_hook', function($atts){ ob_start(); $atts = shortcode_atts( array( 'hook_name' => 'no foo' ), $atts, 'portable_hook' ); do_action($atts['hook_name']); return ob_get_clean(); }); add_filter( 'the_content', 'insert_element', 20 ); function insert_element( $content ) { global $post; $inserted_hook = do_shortcode('[portable_hook hook_name="after_third_paragraph"]'); if ( is_single() && ! is_admin() ) { return prefix_insert_after_paragraph( $inserted_hook, 3, $content ); } return $content; } function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) { $closing_p = '</p>'; $paragraphs = explode( $closing_p, $content ); foreach ($paragraphs as $index => $paragraph) { if ( trim( $paragraph ) ) { $paragraphs[$index] .= $closing_p; } if ( $paragraph_id == $index + 1 ) { $paragraphs[$index] .= $insertion; } } return implode( '', $paragraphs ); }
November 23, 2022 at 4:12 am #2428802PatriciaHello David!
Ok it works π but when I try to copy and paste the code to create the next custom hook I have this erros message: https://ibb.co/VVfd7Hm
thank you!November 23, 2022 at 5:43 am #2428930DavidStaffCustomer SupportOk, you can’t duplicate the code.
If you put it back to the one code where it was working ( and double check that π )Now try adding this: – i set it to the
7
seventh paragraph. That will return a hook titled:after_seventh_paragraph
add_filter( 'the_content', 'insert_element_seventh', 25 ); function insert_element_seventh( $content ) { global $post; $inserted_hook = do_shortcode('[portable_hook hook_name="after_seventh_paragraph"]'); if ( is_single() && ! is_admin() ) { return prefix_insert_after_paragraph( $inserted_hook, 7, $content ); } return $content; }
If that works then add another code for the
after_eleventh_paragraph
add_filter( 'the_content', 'insert_element_eleventh', 30 ); function insert_element_eleventh( $content ) { global $post; $inserted_hook = do_shortcode('[portable_hook hook_name="after_eleventh_paragraph"]'); if ( is_single() && ! is_admin() ) { return prefix_insert_after_paragraph( $inserted_hook, 11, $content ); } return $content; }
November 23, 2022 at 5:49 am #2428939PatriciaHi david, yes the code was working, the only problem is that couldnt duplicate. I will test the new codes and will confirm with you! thank you so much! π and talk soon!
November 23, 2022 at 5:54 am #2428946DavidStaffCustomer SupportAwesome – let us know π
November 24, 2022 at 10:08 am #2431641PatriciaHi David! I am trying the additional codes,
Here is the situation:
1. I created a hook with testimonials with the intention to place it under the 7th paragraph
2. I created another hook with a table to be placed under the 11th paragraphhowever, all placements are showing(repeating) the related post hook. and they appear one after another instead of under paragraphs 7 and 11. you can see it on the link I am sharing! thank you!
November 25, 2022 at 3:38 am #2432667DavidStaffCustomer SupportHmm…. peculiar and we’re to begin with debugging that.
First thing i noticed, in the Query Loop block, the Headline Block with the Date Meta is set to ap
– could you change that toDIV
? This will avoid it getting counted in the content.In the meantime ill try and get my head around what is happening here π
November 26, 2022 at 5:30 am #2435531PatriciaHi David!
Where do you mean the query look block? This is the first block in which I added the 3 suggested articles, correct? If this is the case, I deleted it and added an info box for testing purposes, and the problem persists. the link is in private area!
thank you!
November 28, 2022 at 7:48 am #2439006DavidStaffCustomer SupportSorry for the delay, i just booked myself in to “how not to be an idiot and not check the function names” class lol
So the issue is with the 2 additional snippets i provided here:
Both i have now fixed, can you give them a try ?
November 28, 2022 at 8:03 am #2439234PatriciaSure will give it a try! No worries! You are doing excellent work, David!! π will try and let you know! Thanks
talk soon!
November 28, 2022 at 8:25 am #2439290PatriciaHi David, now, it only displays thee box after the 3rd paragraph.
maybe I am not pasting it correctly? I tried like this
add_shortcode(‘portable_hook’, function($atts){
ob_start();
$atts = shortcode_atts( array(
‘hook_name’ => ‘no foo’
), $atts, ‘portable_hook’ );
do_action($atts[‘hook_name’]);
return ob_get_clean();
});add_filter( ‘the_content’, ‘insert_element_seventh’, 25 );
function insert_element_seventh( $content ) {
global $post;
$inserted_hook = do_shortcode(‘[portable_hook hook_name=”after_seventh_paragraph”]’);
if ( is_single() && ! is_admin() ) {
return prefix_insert_after_paragraph( $inserted_hook, 7, $content );
}
return $content;
}and have also tried just adding this code alone as well
add_filter( ‘the_content’, ‘insert_element_seventh’, 25 );
function insert_element_seventh( $content ) {
global $post;
$inserted_hook = do_shortcode(‘[portable_hook hook_name=”after_seventh_paragraph”]’);
if ( is_single() && ! is_admin() ) {
return prefix_insert_after_paragraph( $inserted_hook, 7, $content );
}
return $content;
}in any case it shows only after the 3rd paragraph!
thank you so so much!
November 28, 2022 at 8:31 am #2439298DavidStaffCustomer SupportOK, remove any snippets you have so far and add:
add_shortcode('portable_hook', function($atts){ ob_start(); $atts = shortcode_atts( array( 'hook_name' => 'no foo' ), $atts, 'portable_hook' ); do_action($atts['hook_name']); return ob_get_clean(); }); add_filter( 'the_content', 'insert_element', 20 ); function insert_element( $content ) { global $post; $inserted_hook = do_shortcode('[portable_hook hook_name="after_third_paragraph"]'); if ( is_single() && ! is_admin() ) { return prefix_insert_after_paragraph( $inserted_hook, 3, $content ); } return $content; } add_filter( 'the_content', 'insert_element_seventh', 25 ); function insert_element_seventh( $content ) { global $post; $inserted_hook = do_shortcode('[portable_hook hook_name="after_seventh_paragraph"]'); if ( is_single() && ! is_admin() ) { return prefix_insert_after_paragraph( $inserted_hook, 7, $content ); } return $content; } add_filter( 'the_content', 'insert_element_eleventh', 30 ); function insert_element_eleventh( $content ) { global $post; $inserted_hook = do_shortcode('[portable_hook hook_name="after_eleventh_paragraph"]'); if ( is_single() && ! is_admin() ) { return prefix_insert_after_paragraph( $inserted_hook, 11, $content ); } return $content; } function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) { $closing_p = '</p>'; $paragraphs = explode( $closing_p, $content ); foreach ($paragraphs as $index => $paragraph) { if ( trim( $paragraph ) ) { $paragraphs[$index] .= $closing_p; } if ( $paragraph_id == $index + 1 ) { $paragraphs[$index] .= $insertion; } } return implode( '', $paragraphs ); }
Then there should be three hooks for you to use:
after_third_paragraph
after_seventh_paragraph
after_eleventh_paragraph
November 28, 2022 at 9:00 am #2439352PatriciaOh No! It is not working :/ not even like this. shows only after_third_paragraph
November 28, 2022 at 9:56 am #2439471DavidStaffCustomer SupportDo you have any cache plugins ? If so can you try clearing those ?
November 28, 2022 at 10:16 am #2439510Patriciayes cleared caching! π
-
AuthorPosts
- You must be logged in to reply to this topic.