Support » Theme: Twenty Twenty » Automatic add reusable blocks

  • Resolved skariko

    (@skariko)


    Hello, i am using Twenty-Twenty theme with Gutemberg editor.

    I want to add on all of my posts a “Reusable block” that i have created (on the link to my page that i added the block is “I COMMENTI SU REDDIT”).

    I don’t want to enter in 50+ posts to add it manually. Is there a way to add it on all my old posts? At the end of the post like the link i have posted?

    I tried also to add the “html” on my singular.php page but it does not show it properly 🙁

    Thanks!

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • How/where are you adding it into singular.php? That is used for both posts/pages so you may be better off adding it into /template-parts/content.php and using is_single() to ensure it is a single post.

    You’ll also want to be using a child theme ( https://developer.wordpress.org/themes/advanced-topics/child-themes/ ) to ensure that your changes aren’t overwritten with any future theme updates.

    Thread Starter skariko

    (@skariko)

    Thank you!
    I made what you said and create a Child Theme with your instruction.

    I made exactly what i want, so i replace <?php comments_template(); ?> with <?php reblex_display_block(1669); ?> (i have installed https://it.wordpress.org/plugins/reusable-blocks-extended/ to have blocks reusable with php). It works like a charm but i have another question if you can help me:

    – After the block, why it re-add the jetpack sharing tool? (you can see an example on the same link of the opening topic).

    EDIT:

    it did the same if i add my own code without that plugin installed, using just this code:

    			<?php
        // get reusable gutenberg block:
        $gblock = get_post( 1669 );
        echo apply_filters( 'the_content', $gblock->post_content );
    ?>
    • This reply was modified 2 years, 3 months ago by skariko.

    Hi, haven’t looked at the Jetpack code close enough yet to see how it works. What settings do you have configured for the Sharing settings in Jetpack for ShareDaddy?

    Thread Starter skariko

    (@skariko)

    Well there is not much settings in jetpack settings, i just active it and enable the sharing forma the social you see and set icons text for the design and shows on posta and page.

    I can open a topic on Jetpack’s forum, it may be a jetpack bug.

    What does the full code look like for your file on the child theme where that is being replicated?

    Thread Starter skariko

    (@skariko)

    Sure, I just replace this <?php comments_template(); ?> on /template-parts/content.php

    Now it looks like this:

    `<?php
    /**
    * The default template for displaying content
    *
    * Used for both singular and index.
    *
    * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
    *
    * @package WordPress
    * @subpackage Twenty_Twenty
    * @since 1.0.0
    */

    ?>

    <article <?php post_class(); ?> id=”post-<?php the_ID(); ?>”>

    <?php

    get_template_part( ‘template-parts/entry-header’ );

    if ( ! is_search() ) {
    get_template_part( ‘template-parts/featured-image’ );
    }

    ?>

    <div class=”post-inner <?php echo is_page_template( ‘templates/template-full-width.php’ ) ? ” : ‘thin’; ?> “>

    <div class=”entry-content”>

    <?php
    if ( is_search() || ! is_singular() && ‘summary’ === get_theme_mod( ‘blog_content’, ‘full’ ) ) {
    the_excerpt();
    } else {
    the_content( __( ‘Continue reading’, ‘twentytwenty’ ) );
    }
    ?>

    </div><!– .entry-content –>

    </div><!– .post-inner –>

    <div class=”section-inner”>
    <?php
    wp_link_pages(
    array(
    ‘before’ => ‘<nav class=”post-nav-links bg-light-background” aria-label=”‘ . esc_attr__( ‘Page’, ‘twentytwenty’ ) . ‘”><span class=”label”>’ . __( ‘Pages:’, ‘twentytwenty’ ) . ‘</span>’,
    ‘after’ => ‘</nav>’,
    ‘link_before’ => ‘<span class=”page-number”>’,
    ‘link_after’ => ‘</span>’,
    )
    );

    edit_post_link();

    // Single bottom post meta.
    twentytwenty_the_post_meta( get_the_ID(), ‘single-bottom’ );

    if ( is_single() ) {

    get_template_part( ‘template-parts/entry-author-bio’ );

    }
    ?>

    </div><!– .section-inner –>

    <?php

    if ( is_single() ) {

    get_template_part( ‘template-parts/navigation’ );

    }

    /**
    * Output comments wrapper if it’s a post, or if comments are open,
    * or if there’s a comment number – and check for password.
    * */
    if ( ( is_single() || is_page() ) && ( comments_open() || get_comments_number() ) && ! post_password_required() ) {
    ?>

    <div class=”comments-wrapper section-inner”>

    <?php
    // get reusable gutenberg block:
    $gblock = get_post( 1669 );
    echo apply_filters( ‘the_content’, $gblock->post_content );
    ?>

    </div><!– .comments-wrapper –>

    <?php
    }
    ?>

    </article><!– .post –>`

    Try removing the apply_filters code so it looks something like this

    <?php
    // get reusable gutenberg block:
    $gblock = get_post( 1669 );
    echo $gblock->post_content;
    ?>
    Thread Starter skariko

    (@skariko)

    It seems works!

    Beautiful, thanks 🙂

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Automatic add reusable blocks’ is closed to new replies.