Shortcode rendering as text not as shortcode should

前端 未结 3 1340
渐次进展
渐次进展 2021-01-25 09:53

I am building a shopping website and I am trying to put a shortcode in that will show the customer a buy button and the quantity of the product the customer wants to purchase. O

3条回答
  •  感动是毒
    2021-01-25 10:30

    Typically your shortcode is getting registered in a plugin or your theme's functions.php file. In a plugin it's often something like:

    add_action('init', 'register_my_shortcode');
    
    function register_my_shortcode(){
      add_shortcode('my_shortcode', 'do_my_shortcode');
    }
    

    And then you'd have a function do_my_short_code() that actually outputs the content. With something like that the shortcode is getting registered via the 'init' hook (http://codex.wordpress.org/Plugin_API/Action_Reference) which is called before WP has started figuring out what template to use, what content to output, etc.

    But some plugins will register the shortcode in a way that it is only available on pages / posts where it's going to potentially be used. For example, I can think of one plugin where they register the shortcode and enqueue some javascripts in the same function. That function checks to see if you're on a particular page before it executes so that the js files are not included unnecessarily all over the place. Since the shortcode registration takes place in the same function it means the shortcode only exists on those pages.

    Anyhow, if the shortcode is showing as existing on your archives page you know that isn't the problem, so check that first and let me know what you find.

提交回复
热议问题