简体   繁体   中英

How can we display a shortcode in a custom post type?

I am trying to add a contact from 7 shortcode into a custom post type, I can add it using 'the_content' filter but the problem is that it will be added to all post types which is not right.

How can i hook into a custom post type only without messing with other post types?

You can add code in PHP also for displaying shortcode, url

 // Use shortcodes in form like Landing Page Template.
 echo do_shortcode( '[contact-form-7 id="91" title="quote"]' );

Or you can directly add into the content in wp Editor of your custom post type, in which post you want to show the shortcode. So it will be shown for that post only in single.php .

Hope this will helps you.

  1. Add your custom post type single template. Naming structure will be like following,

single-{custom-post-type}.php

  1. On this template after the loop or the place that is suitable for you you can add the shortcode.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM