Below, you’ll find a detailed guide on how to add the Insert Headers And Footers 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 Insert Headers And Footers Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Insert Headers And Footers Plugin and the shortcodes it provides:
"WPCode – Insert Headers and Footers + Custom Code Snippets – WordPress Code Manager is a robust tool that simplifies the insertion of custom codes to your WordPress site's headers and footers."
- [wpcode]
Insert Headers And Footers [wpcode] Shortcode
The ‘wpcode’ shortcode is a powerful tool from the Insert Headers and Footers plugin. It allows users to execute a specific WPCode_Snippet based on the ‘id’ attribute passed. If the snippet is active and meets conditional logic rules, the shortcode will return the snippet output. Otherwise, it will return an empty string. This shortcode is highly useful for implementing dynamic content.
Shortcode: [wpcode]
Parameters
Here is a list of all possible wpcode shortcode parameters and attributes:
id
– A unique number that identifies the specific snippet.wpcode_source
– Defines the source of the snippet, default is ‘shortcode’.
Examples and Usage
Basic example – A simple usage of the wpcode shortcode to display a specific snippet by its ID.
[wpcode id=3 /]
Advanced examples
Using the shortcode to display a snippet by its ID, but also specifying the source of the snippet as ‘shortcode’. This can be useful for tracking where the snippet is being used.
[wpcode id=3 wpcode_source='shortcode' /]
Using the shortcode to display a snippet by its ID, and applying conditional logic rules. If the rules are not met, the snippet will not be displayed.
[wpcode id=3 wpcode_source='shortcode' use_conditional_logic=true /]
PHP Function Code
In case you have difficulties debugging what causing issues with [wpcode]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'wpcode', 'wpcode_shortcode_handler' );
Shortcode PHP function:
function wpcode_shortcode_handler( $args, $content, $tag ) {
$atts = wp_parse_args(
$args,
array(
'id' => 0,
'wpcode_source' => 'shortcode',
)
);
if ( 0 === $atts['id'] ) {
return '';
}
$snippet = new WPCode_Snippet( absint( $atts['id'] ) );
if ( ! $snippet->is_active() ) {
return '';
}
// Let's check that conditional logic rules are met.
if ( $snippet->conditional_rules_enabled() && ! wpcode()->conditional_logic->are_snippet_rules_met( $snippet ) && apply_filters( 'wpcode_shortcode_use_conditional_logic', true ) ) {
return '';
}
$shortcode_location = apply_filters( 'wpcode_get_snippets_for_location', array( $snippet ), 'shortcode' );
if ( empty( $shortcode_location ) ) {
return '';
}
$snippet->location = $atts['wpcode_source'];
do_action( 'wpcode_shortcode_before_output', $snippet, $atts, $content, $tag );
return wpcode()->execute->get_snippet_output( $snippet );
}
Code file location:
insert-headers-and-footers/insert-headers-and-footers/includes/shortcode.php
Conclusion
Now that you’ve learned how to embed the Insert Headers And Footers 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.
Leave a Reply