Display shortcode on specific CPT listing page & detail page

This topic contains 5 replies, has 3 voices, and was last updated by  Paolo 6 years, 11 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #377672

    Paul Ceppaglia
    Expired Member
    Post count: 29

    Hi,

    I have 2 CPT types.

    I would like to display a shortcode on the listings and details pages for just 1 of the CPT.

    I have already configured my site to hide advertisements (text widgets) based on the package ID, so I figure there should be a similar way to render a shortcode based on the cpt type.

    Any help would be greatly appreciated!

    Thanks,
    Paul

    #377688

    Kor
    Moderator
    Post count: 16516

    Hi Paul,

    Check out this section of the documentation as it covers this https://wpgeodirectory.com/docs/core-shortcodes/#ctp-cats

    Thanks!

    #377750

    Paul Ceppaglia
    Expired Member
    Post count: 29

    Hi Kor,

    Thanks for replying, but I think you’ve misunderstood my request.

    I’m not trying to insert a GD shortcode.

    Basically what I want to do is display a different plugin’s shortcode (which will display a table or graphic) on a CPT listings page IF, AND ONLY IF, it’s a particular CPT.

    So, I’m wondering if there’s a solution similar to this:

    https://wpgeodirectory.com/docs/common-code-snippets/#package

    In this example, I inserted this code:

    
    
    // add the package id to the body
    add_filter( 'body_class', 'my_add_package_class',10,1 );
    function my_add_package_class($class){
        global $post;
        if (geodir_is_page('detail') && isset($post->package_id)) {
            $class[] = "gd-package-id-".$post->package_id;
        }
        return $class;
    }

    into my child theme’s functions.php to allow me to show/hide text widgets based on the value of gd-package-id.

    Is there a similar piece of code that will allow me to show/hide content elements on a listings page (and a listings detail page) based on the CPT type?

    Thanks,
    Paul

    #377764

    Paolo
    Site Admin
    Post count: 31206

    Hi,

    yes you can, try this:

    
    
    add_action( 'geodir_details_main_content', 'my_custom_action',35);
    
    function my_custom_action(){
    if ( 'gd_place' == get_post_type() ) { // echo your shortcode here };
    }
    

    Let us know how it goes,

    Thanks

    #377819

    Paul Ceppaglia
    Expired Member
    Post count: 29

    Hi Paolo,

    Thanks very much. That works!

    –Paul

    #377885

    Paolo
    Site Admin
    Post count: 31206

    You are welcome 🙂

Viewing 6 posts - 1 through 6 (of 6 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket