Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • Charudatta Mundale
    Participant

    Hello Akash,

    We are using shortcoder plug-in for our documentation platform. We have one requirement. There is one topic which is connected to two different categories.

    We want to conditionalize the post content based on the currently visible category. So, we want to use shortcoder plug-in where we will write the snippet to check the current category of the post and decide the content that will be shown to the user when they open the post.

    Is it possible for you to give some idea on this? how we can use shortcoder plug-in.

    -Charudatta M.

    Hi Charudatta,

    Thanks for using Shortcoder.
    With shortcoder plugin we cannot achieve “dynamic” conditions.

    Shortcoder is meant to create small shortcodes for big HTML/CS/JS snippets.

    Adding conditions is basically creating a programming language.

    I would suggest create your own shortcode and call shortcoder shortcodes like below.

    /* Create a shortcode which will conditional print shortcoder shortcode */
    function sc_condition_function($args){
        
        $category = get_the_category();
        $firstCategory = $category[0]->cat_name;
        
        if( $firstCategory = 'my_category' ){
            echo do_shortcode( '[sc name="sc1"]' );
        }else{
            echo do_shortcode( '[sc name="sc2"] );
        }
        
    }
    add_shortcode('sc_condition', 'sc_condition_function');

    Thanks,
    Aakash

    Charudatta Mundale
    Participant

    Thank you Akash for your quick reply. I will check the solution that you suggested.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Subscribe for updates

Get updates on the WordPress plugins, tips and tricks to enhance your WordPress experience. No spam. View newsletter