- This topic has 12 replies, 4 voices, and was last updated 5 months, 2 weeks ago by
David.
-
AuthorPosts
-
October 4, 2022 at 1:28 pm #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.
ThanksOctober 4, 2022 at 1:46 pm #2363281Leo
StaffCustomer SupportHi 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 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 4, 2022 at 9:54 pm #2363544Dan
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 ); }
October 4, 2022 at 10:09 pm #2363560Dan
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 );
October 4, 2022 at 10:29 pm #2363579Fernando 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?
October 4, 2022 at 10:46 pm #2363592Dan
Hey, I am referring to line breaks, with the function active all post formatting disappears. It’s not every post though, just random posts.
October 4, 2022 at 10:48 pm #2363593Dan
I do have the function disabled now. One post that is doing it is https://www.fountainof30.com/test-post-sunday/
October 4, 2022 at 10:50 pm #2363595Fernando Customer Support
I see. Can you reenable the function now again?
October 5, 2022 at 4:21 am #2363883Dan
Ok, function is enabled again for you.
October 5, 2022 at 5:35 pm #2364624Fernando 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.
October 7, 2022 at 6:06 am #2366173Dan
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.
October 7, 2022 at 6:12 am #2366175Dan
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.
October 7, 2022 at 6:46 am #2366201David
StaffCustomer SupportHi 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.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.