Shortcoder Shortcode

Below, you’ll find a detailed guide on how to add the Shortcoder — Create Shortcodes for Anything Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Shortcoder — Create Shortcodes for Anything Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Shortcoder — Create Shortcodes for Anything Plugin and the shortcodes it provides:

Plugin Icon
Shortcoder — Create Shortcodes for Anything

"Shortcoder — Create Shortcodes for Anything is a versatile WordPress plugin that allows you to generate shortcodes for any element. Customize your content and streamline your site with this user-friendly tool."

★★★★☆ (215) Active Installs: 100000+ Tested with: 6.3.2 PHP Version: 5.3
Included Shortcodes:
  • [sc]

Shortcoder — Create Shortcodes for Anything [sc] Shortcode

The Shortcoder plugin shortcode is a dynamic tool that executes a specific function, dictated by the defined attributes. This shortcode checks if any shortcodes are defined. If not, it returns a comment, ‘No shortcodes are defined’. It then identifies the shortcode based on the given attributes. If the shortcode is not an array or if it’s nested within itself, the shortcode is returned directly. Otherwise, the shortcode content is modified based on the display condition, shortcode parameters, WordPress parameters, and custom fields. The modified content is then returned. The shortcode also triggers actions before and after its execution.

Shortcode: [sc]

Examples and Usage

Basic example – A simple usage of the shortcode could be to display a specific post by referencing its ID.

[sc id="123" /]

Advanced examples

1. Using the shortcode to display a post by referencing both ID and post type. The shortcode will first try to load the post by its ID, but if not found, it will try to load by post type.

[sc id="123" type="post" /]

2. You can also use the shortcode to display a specific part of a post, such as the title, by using the ‘part’ attribute.

[sc id="123" part="title" /]

3. The shortcode can be used to display multiple posts by specifying their IDs separated by commas.

[sc id="123,456,789" /]

4. You can also use the shortcode to display posts from a specific category by using the ‘category’ attribute.

[sc category="news" /]

5. The shortcode can be used to display posts in a specific order by using the ‘order’ attribute. The value can be ‘asc’ for ascending order or ‘desc’ for descending order.

[sc category="news" order="desc" /]

These examples illustrate the flexibility and power of shortcodes. With the right parameters, you can display any content you want in any way you want.

PHP Function Code

In case you have difficulties debugging what causing issues with [sc] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'sc', array( __CLASS__, 'execute_shortcode' ) );

Shortcode PHP function:

function execute_shortcode( $atts, $enclosed_content = null ){

        $atts = (array) $atts;
        $shortcodes = self::get_shortcodes();

        if( empty( $shortcodes ) ){
            return '<!-- No shortcodes are defined -->';
        }

        $shortcode = self::find_shortcode( $atts, $shortcodes );

        $shortcode = apply_filters( 'sc_mod_shortcode', $shortcode, $atts, $enclosed_content );
        do_action( 'sc_do_before', $shortcode, $atts );

        if( !is_array( $shortcode ) ){
            return $shortcode;
        }

        // Prevent same shortcode nested loop
        if( self::$current_shortcode == $shortcode[ 'name' ] ){
            return '';
        }
        self::$current_shortcode = $shortcode[ 'name' ];

        $sc_content = $shortcode[ 'content' ];
        $sc_settings = $shortcode[ 'settings' ];

        if( !self::can_display( $shortcode ) ){
            $sc_content = sprintf( '<!-- Shortcode [%s] does not match the conditions -->', self::$current_shortcode );
        }else{
            $sc_content = self::replace_sc_params( $sc_content, $atts );
            $sc_content = self::replace_wp_params( $sc_content, $enclosed_content );
            $sc_content = self::replace_custom_fields( $sc_content );
            $sc_content = do_shortcode( $sc_content );
        }

        $sc_content = apply_filters( 'sc_mod_output', $sc_content, $atts, $sc_settings, $enclosed_content );
        do_action( 'sc_do_after', $shortcode, $atts );

        self::$current_shortcode = false;

        return $sc_content;

    }

Code file location:

shortcoder/shortcoder/shortcoder.php

Conclusion

Now that you’ve learned how to embed the Shortcoder — Create Shortcodes for Anything Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *