- This topic has 51 replies, 5 voices, and was last updated 3 years, 3 months ago by
David.
-
AuthorPosts
-
November 18, 2022 at 7:17 am #2421491
Patricia
Hi my friends hope all is well!
I would like to add an widget area to the content in the sinle page,
like in the example in this link when there is the ‘trending’ box, on the third paragraph
can you please help? thanksNovember 18, 2022 at 11:39 am #2422030Leo
StaffCustomer SupportHi there,
I don’t believe it’s possible using a widget but you can try using a hook:
https://generatepress.com/forums/topic/element-after-first-paragraph/#post-1937353November 18, 2022 at 2:41 pm #2422213Patricia
Hi Leo that might work.I should substitute after_first_paragraph to after_third_paragraph? thanks
November 18, 2022 at 2:42 pm #2422214Patricia
and can I add the PHP snippet to the hook and then select it to be displayed after_third_paragraph? is that? thank you
November 18, 2022 at 2:45 pm #2422215Patricia
but I dont understand where will add the css code?
November 18, 2022 at 2:46 pm #2422216Patricia
ah ok… I can paste the PHP snippet on the settings.php and then it will generate a hook after the paragraph I want. I think it is that 🙂 will test now!
November 18, 2022 at 2:53 pm #2422222Patricia
It is working really well thank you!
November 18, 2022 at 2:54 pm #2422223Patricia
what if I want to do it more than once? For example
after the 3rd paragraph, then after the 10th and then after the 13th and so on? thanks
November 18, 2022 at 3:17 pm #2422244Ying
StaffCustomer SupportYou can modify the code for the 10th and 13th, so there’ll be 3 code snippets.
November 18, 2022 at 4:13 pm #2422260Patricia
I thought that would be too long will it affect page speed?
November 18, 2022 at 4:14 pm #2422261Patricia
well I will test and see what happens thank you so much! have a lovelly weekend
November 18, 2022 at 5:12 pm #2422284Patricia
Hi guys still with this code, I am trying to add a related post with thumbnail on the left and title on the right. is that possible to achieve this and add it to this hook? thank you!
November 19, 2022 at 7:26 am #2422910Patricia
HI guys it is solved. 🙂 found how to use it. thanks! have a lovely weekend
November 19, 2022 at 11:16 am #2423255Patricia
Hello guys, still hassling with this issue here..
I noticed that on generateblock (using pro) it is possible to use a custom hook. but any time i add this custom hook, the site gets down. It only works if I create a normal hook (not from generateblocks). but does not allow me to do what I want which is: only one featured post on the 3rd paragraph (ideally a related post).
howeer when I try the normal hook, I am using this code to display the 3rd paragraph instead of the 1st. But it only show the text on the frist paragraph.
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 );
}My question is, how can I add one featured post (related post) with thumbnail on the left and excerpt on the right, after the 3rd paragraph of each post? Thanks
November 19, 2022 at 11:18 am #2423256Patricia
here is an example of what I want, she puts it in the 4th paragraph. thanks
-
AuthorPosts
- You must be logged in to reply to this topic.