Site logo

[Resolved] adding widget area to 3rd paragraph in the single page

Home Forums Support [Resolved] adding widget area to 3rd paragraph in the single page

Home Forums Support adding widget area to 3rd paragraph in the single page

Viewing 15 posts - 1 through 15 (of 52 total)
  • Author
    Posts
  • #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? thanks

    #2422030
    Leo
    Staff
    Customer Support

    Hi 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-1937353

    #2422213
    Patricia

    Hi Leo that might work.I should substitute after_first_paragraph to after_third_paragraph? thanks

    #2422214
    Patricia

    and can I add the PHP snippet to the hook and then select it to be displayed after_third_paragraph? is that? thank you

    #2422215
    Patricia

    but I dont understand where will add the css code?

    #2422216
    Patricia

    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!

    #2422222
    Patricia

    It is working really well thank you!

    #2422223
    Patricia

    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

    #2422244
    Ying
    Staff
    Customer Support

    You can modify the code for the 10th and 13th, so there’ll be 3 code snippets.

    #2422260
    Patricia

    I thought that would be too long will it affect page speed?

    #2422261
    Patricia

    well I will test and see what happens thank you so much! have a lovelly weekend

    #2422284
    Patricia

    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!

    #2422910
    Patricia

    HI guys it is solved. 🙂 found how to use it. thanks! have a lovely weekend

    #2423255
    Patricia

    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

    #2423256
    Patricia

    here is an example of what I want, she puts it in the 4th paragraph. thanks

Viewing 15 posts - 1 through 15 (of 52 total)
  • You must be logged in to reply to this topic.