Viewing 4 replies - 1 through 4 (of 4 total)
  • Sounds like you want to insert a block programmatically in all of your posts?

    The block are only parts of the interface. Its all stored as HTML when saved and parsed out back to blocks when retrieved to show in the UI.

    Example:

    <!-- wp:paragraph {"dropCap":true,"style":{"elements":{"link":{"color":{"text":"var:preset|color|orange"}}},"typography":{"lineHeight":"1.8"}},"backgroundColor":"gray","textColor":"blue","fontSize":"small"} -->
    
    <p class="has-drop-cap has-blue-color has-gray-background-color has-text-color has-background has-link-color has-small-font-size" style="line-height:1.8">Here is some text.</p>
    
    <!-- /wp:paragraph -->

    So, either you can programmatically insert the right html for the block you want & save the post. This would have to be done by looping over all the posts that you want to modify and change post_content on them before saving the post again. Look into get_post() for that.

    OR you can use the_content filter to just inject some HTML in between. You would need some checks like is_post() to limit where you filter does the change. Example:

    function custom_content_filter( $content ) {
      // Check if we're on a single post
      if ( is_singular( 'post' ) ) {
        return $modified_content;
      }
    
      // Default content for other contexts
      return $content;
    }
    add_filter( 'the_content', 'custom_content_filter' );
    

    Hi @sharonbeyond,

    By the middle of every single post, do you mean in between the content of the post, in the post page itself? Or do you mean it would show between posts, in a page that shows the listing of posts?

    I’m assuming you want it to display in between the content of the post, in a single post page. In the example page you linked above, are you referring to the “?Necesita ayuda para entender la Biblia?” section?

    To display content in between a post, WordPress needs to know exactly where you want it to display. (After three paragraphs? In the “middle” of all paraghraphs? etc).

    The easiest way to achieve this is to edit the post so that it contains the block in the exact position you want it. You’d have to this for all existing posts, and for all new posts going forward.

    I’m sure there would be ways to achieve this automatically, without requiring editing every post, but that would likely involve coding a plugin. Alternatively, you could search the plugin directory for existing plugins that achieve this, I found this one which looks like it could do that, but I haven’t tested it myself.

    • This reply was modified 1 year, 6 months ago by Paulo Pinto.
    Thread Starter sharonbeyond

    (@sharonbeyond)

    Hi@psrpinto, Thank you.
    > By the middle of every single post, do you mean in between the content of the post, in the post page itself? Or do you mean it would show between posts, in a page that shows the listing of posts?

    Yes i need that reusable block to be added in the middle of the every single post content as in the give reference.
    In the given reference url, theme is different and that block is added in the theme code whereas this url https://bfablogesdev.wpengine.com/(page i need help) uses a reusable block so now i need to add that same in the customised theme code we’re using

    > ?In the?example page?you linked above, are you referring to the “?Necesita ayuda para entender la Biblia?” section?
    Yes you’re right referring to this section “?Necesita ayuda para entender la Biblia?” section?

    >I’m sure there would be ways to achieve this automatically, without requiring editing every post, but that would likely involve coding a plugin. Alternatively, you could search the?plugin directory?for existing plugins that achieve this, I found?this one?which looks like it could do that, but I haven’t tested it myself.
    Not able to find a appropriate plugin to do this, Only way found was manually adding the blcok for every single post but that’s not quite possible

    • This reply was modified 1 year, 6 months ago by sharonbeyond.
    • This reply was modified 1 year, 6 months ago by sharonbeyond.
    Thread Starter sharonbeyond

    (@sharonbeyond)

    @ashfame Thank you. We’ll try your suggestion.

    • This reply was modified 1 year, 6 months ago by sharonbeyond.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Reusable block need to add in middle of every single post’ is closed to new replies.