[Support request] When theme is active with Yoast active posts don’t show page breaks

Home Forums Support [Support request] When theme is active with Yoast active posts don’t show page breaks

Home Forums Support When theme is active with Yoast active posts don’t show page breaks

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #2363273
    Dan

    Hello, there seems to be something causing page breaks to not show on posts in preview or when published. If I disable Yoast they come back, if I disable the theme with Yoast active they come back. It’s very odd. You can see it in this post. https://www.fountainof30.com/test-post-sunday/
    I have tested this with all other plugins disabled.

    Let me know your thoughts.
    Thanks

    #2363281
    Leo
    Staff
    Customer Support

    Hi Dan,

    That sounds strange. Yoast is a very popular plugin and we have not had any other reports on this.

    Have you tried disabling all plugins except Yoast to check? Make sure to deactivate all custom functions and activate the parent theme if you are using a child theme as well.

    Let me know 🙂

    #2363544
    Dan

    Ok, one thing I did not test was disabling the child theme of GP. With the child theme disabled everything worked as it should.
    Below is my functions file and the 2 snippets I have. The first is the RTL Stylesheet, I don’t think this is needed.
    The second I got from this GP Forum Post.
    I was wanting to add a newsletter signup hook after the 3rd paragraph on all posts.

    I am not sure why either of these woulc cause this issue. When I clear the functions file the child theme works like it should.
    Any ideas?

    <?php
    /**
     * GeneratePress child theme functions and definitions.
     *
     * Add your custom PHP in this file. 
     * Only edit this file if you have direct access to it on your server (to fix errors if they happen).
     */
    
    function generatepress_child_enqueue_scripts() {
    	if ( is_rtl() ) {
    		wp_enqueue_style( 'generatepress-rtl', trailingslashit( get_template_directory_uri() ) . 'rtl.css' );
    	}
    }
    add_action( 'wp_enqueue_scripts', 'generatepress_child_enqueue_scripts', 100 );
    
    /**Add custom hook for in post newsleter signup**/
    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_3_paragraph"]');
        if ( is_single() && ! is_admin() ) {
            return prefix_insert_after_paragraph( $inserted_hook, 6, $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 );
    }
    #2363560
    Dan

    I updated the function code to this. It still strips the breaks from the paragraph in the mentioned post.

    <?php
    /**
     * GeneratePress child theme functions and definitions.
     *
     * Add your custom PHP to this file. 
     * Only edit this file if you have direct access to it on your server (to fix errors if they happen).
     */
    
    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_3_paragraph"]');
        if ( is_single() && ! is_admin() ) {
            return prefix_insert_after_paragraph( $inserted_hook, 6, $content ) . $inserted_hook;
        }
        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 );
    }
    
    add_filter( 'generate_hooks_list', function($hooks){
        $hooks['content']['hooks'][] = 'after_first_paragraph_and_content';
        return $hooks;
    }, 99,1 );
    #2363579
    Fernando
    Customer Support

    Hi Dan,

    To clarify, are you referring to Page or line breaks?

    Can you try temporarily disabling the function, and I’ll see what occurs?

    #2363592
    Dan

    Hey, I am referring to line breaks, with the function active all post formatting disappears. It’s not every post though, just random posts.

    #2363593
    Dan

    I do have the function disabled now. One post that is doing it is https://www.fountainof30.com/test-post-sunday/

    #2363595
    Fernando
    Customer Support

    I see. Can you reenable the function now again?

    #2363883
    Dan

    Ok, function is enabled again for you.

    #2364624
    Fernando
    Customer Support

    Can you try setting “Post Mailchimp” element to draft temporarily? Then, create a new element with just a Headline Block, and hook it to the same custom hook.

    Let us know how it goes.

    For reference, I tested your code on my site, and I didn’t encounter the issue.

    #2366173
    Dan

    Hey Fernando, sorry for the delay, I got that code pulled out and added a headline block and it is doing the same exact thing on that post. I did exclude all other posts except the https://www.fountainof30.com/test-post-sunday/ post to test.

    #2366175
    Dan

    Also just to add some more context. The issue corrects itself when I deactivate the Yoast plugins with all others active. With all other plugins besides GP Premium and Generateblocks and Yoast disabled the problem is still active.

    #2366201
    David
    Staff
    Customer Support

    Hi there,

    chances are that Yoast is also using the_content filter to do its stuff. Which is conflicting with the function you’re using to insert an item after the 3rd paragraph.

    You may want to look at using the Ad Inserter Plugin to do the inserting of content after the paragraph. They use a much more robust method then the one in your function:

    https://en-gb.wordpress.org/plugins/ad-inserter/

    If that still conflicts then i would suggest Yoast needs to look into it.

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