- This topic has 51 replies, 5 voices, and was last updated 3 years, 3 months ago by
David.
-
AuthorPosts
-
November 19, 2022 at 12:51 pm #2423320
Leo
StaffCustomer SupportThe PHP code should be not added using one of these methods only:
Adding PHP: https://docs.generatepress.com/article/adding-php/It should not be added through hooks or theme files.
And CSS can be added using one of these methods:
Adding CSS: https://docs.generatepress.com/article/adding-css/Please make sure the code is added correctly first.
November 20, 2022 at 5:18 am #2423908Patricia
I am creating it on generateblocks pro and then I set the custom hook to the third paragraph but every time i do it, the site goes down. any thoughts on it? thanks
November 20, 2022 at 1:12 pm #2424505Leo
StaffCustomer SupportI thought in a previous reply you’ve mentioned that it worked?
What changed after?
November 20, 2022 at 4:16 pm #2424613Patricia
1st – I added the php code to the functions and created a custom element hook placement under the 3rd paragraph.
2nd – Then I created a hook and set it to be displayed on a custom hook. initially it worked fine, under the 3rd paragraph with plain text. But I am looking to display one blog post suggestion under the third paragraph () Initially when I said it worked, it actually worked with plain text, but it was not what I was trying to achieve.
So, After experimenting with it a little ,I managed to create the blog suggestion box and it looked exactly as I wanted by using genarateblocks, grid, and custom loop.
In this block a set the grid as I wanted, got the look and configuration to what I wanted. So far so good. Next step would be to place it on the custom hook to place it under 3rd parapragh but any time I do it the site goes down.
Does that make more sense now? many thanks
November 21, 2022 at 3:49 am #2425121David
StaffCustomer SupportHi there,
If you set the Query Loop to display just the Title, does it work ok ?
November 21, 2022 at 4:26 am #2425159Patricia
HI David it is working like you suggested. I have another issue tho; despite adapting the php code to show after the 3rd paragraph, it is being displayed only after the 1st paragraph….
here is the code:
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_featured_image’, 20 );
function insert_featured_image( $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 + 3 ) {
$paragraphs[$index] .= $insertion;
}
}
return implode( ”, $paragraphs );
}November 21, 2022 at 5:19 am #2425243David
StaffCustomer SupportOK, so the excerpt won’t work, as its a trimmed version of
the_contentwhich means the excerpt is also being filtered by your code, which is creating an infinite loop.Are you ok with just the title? ( i am kinda hoping for the answer to be yes lol )
Where can i see the post that has it inserted after the 1st paragraph ?
November 21, 2022 at 9:08 am #2425807Patricia
HI David. Yes it is ok if we leave only the title. But would be really nice if I am able to inject these boxes in between paragraphs, not only after the 3rd but after other paragraphs in the content. Here is a link of the staging site, I am sharing in the private box please let me know if you are able to open it. Many thanks
November 22, 2022 at 5:53 am #2427091David
StaffCustomer SupportCouple of questions:
1. What method are you using to insert the adverts?
2. And if we can inject after multiple paragraphs, will the each injected content be different to the other content ?
November 22, 2022 at 6:11 am #2427113Patricia
1. What method are you using to insert the adverts? the adverts are displayed by mediavine, they take care of it; but I want to add normal content boxes or related articles. do you know what I mean?
here is the link on how it is now: https://themakeuporg.bigscoots-staging.com/simple-skincare-routine/
it is being displayed after the first paragraph, but I’d like it to be after the 3rd.
2. And if we can inject after multiple paragraphs, will the each injected content be different to the other content ?
yes it would be different for example:
– after the 3rd paragraph: 1 recommended post
– after the 7th paragraph: 1 call to action box to subscribe
– after the 11th paragraph: 1 call to action box to follow on social mediaHope that makes sense 🙂
Many thanks and talk to you soon!
November 22, 2022 at 8:19 am #2427522David
StaffCustomer SupportOK 🙂
Lets see if we can fix the positioning first:
What happens if you increase the3in the PHP Snippet to a greater number eg .5does the content move ?November 22, 2022 at 8:37 am #2427560Patricia
Hi David!
Unfortunatelly it doesnt move :/
November 22, 2022 at 8:39 am #2427564Patricia
it is intriguing because the first time I tested this code it worked fine under de 3rd paragraph…I havent installed anything after that..
November 22, 2022 at 8:49 am #2427588David
StaffCustomer SupportWhen you tested the code – was that on a live site with the adverts ?
November 22, 2022 at 9:06 am #2427628Patricia
was that on a live site with the adverts ? yes I was testing in live site then after it shut down the site I decided to test on staging
-
AuthorPosts
- You must be logged in to reply to this topic.