• Hello World!! here the topic, i’ve created a function to display a shortcode that display another shortcode depend the language. The shortcode work alone but the second one not working. There are identical function i don’t know why the RegisterForm shortcode doesn’t work and the ProjectForm is working

    <?php
    function getProjectForm_shortcode($atts, $content = ""){
      $current_language = get_locale();
    
      if( $current_language == 'en_EN' ){
          if ($content) {
            $content = do_shortcode('[gravityform id="4" title="false"]');
            return $content;
          }
      }
      if( $current_language == 'fr_FR' ){
        $content = do_shortcode('[gravityform id="3" title="false"]');
        return $content;
      }
    }
    add_shortcode( 'getProjectForm', 'getProjectForm_shortcode' );
    
    // Register shortcode
    
    

    function getRegisterForm_shortcode($atts, $content = “”){

    $current_language = get_locale();

    if( $current_language == ‘en_EN’ ){

    $content = do_shortcode(‘[gravityform id=”2″ title=”true”]’);
    return $content;
    }

    if( $current_language == ‘fr_FR’ ){
    $content = do_shortcode(‘[gravityform id=”1″ title=”true”]’);
    return $content;
    }
    }
    add_shortcode( ‘getRegisterForm’, ‘getRegisterForm_shortcode’ );`
    ?>`

    If you have a better approach, i will be glad to hear you

    Thanks in advance

Viewing 1 replies (of 1 total)
  • By default, WordPress doesn’t allow you to use a shortcode within a shortcode (or in other words, nested shortcode). However, with a simple tweak on your functions.php file, you can make it happen.

    add_shortcode("my_text", "my_text");
    function my_text() {
        return 'nested shortcode';
    }
     
    function my_link($atts, $content = null) {
        extract(shortcode_atts(array(
            "href" => 'https://'
        ), $atts));
        return '<a href="'.$href.'">'.do_shortcode($content).'</a>';
    }
    add_shortcode("link", "my_link");

    Source: isitwp.com

    Alternatively, you could take a look at the Nested Shortcodes by Outerbridge plugin to see how they achieve this.

    I hope this helps.

Viewing 1 replies (of 1 total)
  • The topic ‘Create multiple Shortcodes with nested shortcode’ is closed to new replies.