Below, you’ll find a detailed guide on how to add the Scripts n Styles Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Scripts n Styles Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Scripts n Styles Plugin and the shortcodes it provides:
"Scripts n Styles is a versatile WordPress plugin that allows users to easily add custom scripts and styles to individual posts, pages or custom post types, enhancing your site's functionality."
- [sns_shortcode]
- [sns_shortcode]
Scripts n Styles [sns_shortcode] Shortcode
The Scripts-n-Styles shortcode is a handy tool for customizing your WordPress content. It fetches specific post data, checks for any custom shortcodes, and returns the output. The ‘sns_shortcode’ extracts attributes from the shortcode, checks if there are any saved shortcodes related to the post, and then outputs the shortcode content. If no shortcode is found, it outputs the original content.
Shortcode: [sns_shortcode]
Parameters
Here is a list of all possible sns_shortcode shortcode parameters and attributes:
name
– Identifier of the shortcode or hoop to outputcontent
– Default content if no matching shortcode or hoop is found
Examples and Usage
Basic example – The shortcode is used to retrieve a specific post’s metadata based on its ID. In this case, the ID is passed as a parameter to the shortcode.
[sns_shortcode name=1 /]
Advanced examples
Here, the shortcode is used to retrieve a specific post’s metadata based on its ID. If the metadata does not exist, the shortcode will return the content passed within the shortcode tags.
[sns_shortcode name=1]Fallback content here[/sns_shortcode]
In this example, the shortcode is used to retrieve a specific post’s metadata based on its ID. If the metadata does not exist, the shortcode will try to retrieve the global ‘hoops’ option based on the same ID. If both attempts fail, the shortcode will return the content passed within the shortcode tags.
[sns_shortcode name=1]Fallback content here[/sns_shortcode]
Please note that in all examples, the ‘name’ attribute represents the ID of the post. You need to replace ‘1’ with the ID of the post for which you want to retrieve the metadata.
PHP Function Code
In case you have difficulties debugging what causing issues with [sns_shortcode]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'sns_shortcode', array( __CLASS__, 'shortcode' ) );
Shortcode PHP function:
function shortcode( $atts, $content = null ) {
global $post;
extract( shortcode_atts( array( 'name' => 0, ), $atts ) );
$output = '';
$options = get_option( 'SnS_options' );
$hoops = isset( $options['hoops']['shortcodes'] ) ? $options['hoops']['shortcodes'] : array();
if ( isset( $post->ID ) ) {
$SnS = get_post_meta( $post->ID, '_SnS', true );
$shortcodes = isset( $SnS['shortcodes'] ) ? $SnS[ 'shortcodes' ]: array();
}
if ( isset( $shortcodes[ $name ] ) )
$output .= $shortcodes[ $name ];
else if ( isset( $hoops[ $name ] ) )
$output .= $hoops[ $name ];
if ( ! empty( $content ) && empty( $output ) )
$output = $content;
$output = do_shortcode( $output );
return $output;
}
Code file location:
scripts-n-styles/scripts-n-styles/scripts-n-styles.php
Conclusion
Now that you’ve learned how to embed the Scripts n Styles Plugin shortcodes, 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.
Leave a Reply