Support » Theme: Astra » Custom post type template

  • Resolved theguitarlesson

    (@theguitarlesson)


    Hi,

    I am trying to create a Custom post type template.

    Sticking a single-MyCustomPostType.php in the child theme does not work, because you use template parts to build the post page.

    I need to insert my own PHP code onto the Custom post type primary content area.

    How can I do this?

    I tried this, but it had no effect:
    remove_action( 'astra_entry_content_single', 'astra_entry_content_single' );

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi @theguitarlesson,

    Why don’t you just use a plugin like Custom Post Type UI plugin? It’s easy.

    I hope it will help.

    Kind regards,
    Herman 🙂

    Thread Starter theguitarlesson

    (@theguitarlesson)

    Thanks, but that just registers the custom post type.
    My custom template is complicated, I need to be able to display a lot of variables using PHP, so it doesn’t help.

    Hi @theguitarlesson,

    What if you use Hooks to display those variables on your CPT? Please refer to this page.

    I hope it helps.

    Kind regards,
    Herman 🙂

    Thread Starter theguitarlesson

    (@theguitarlesson)

    Hi,
    That’s what I tried to do, but it didn’t seem to work. This is the reason I tried getting help from the makers of Astra.

    Hi @theguitarlesson,

    Sorry for the delay.

    I noticed that you opened a ticket for a similar query thru our Support Portal. If this thread is the same as the one on the ticket, please continue the communication using the ticket. Otherwise, please reply to this thread.

    Please let us know.

    Kind regards,
    Herman 🙂

    Thread Starter theguitarlesson

    (@theguitarlesson)

    Support from Astra Pro helped me figure this out, here is the code:

    
    // Remove Astra content from Custom Post Type page
    
    add_action('wp', 'remove_astra_content_from_cpt');
        
        function remove_astra_content_from_cpt(){
            if ( is_singular( 'NAMEOFYOURCUSTOMPOSTTYPEGOESHERE' ) ) {
                remove_action( 'astra_entry_content_single', 'astra_entry_content_single_template');
            }
        }
    
        
    function add_cpt_content() {
    
        // bail if this current post type is different.
        if ( is_singular( 'NAMEOFYOURCUSTOMPOSTTYPEGOESHERE' ) ) {
            
            ?>
            <!-- Your custom HTML markup here -->
            <p>My custom theme HTML at astra_entry_content_before</p>	
    
            <?php
            
        }
    }
    
    add_action( 'astra_entry_top', 'add_cpt_content' );

    `

    Hope this helps somebody 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom post type template’ is closed to new replies.