Below, you’ll find a detailed guide on how to add the Ko-fi Button 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 Ko-fi Button Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Ko-fi Button Plugin and the shortcodes it provides:
"Ko-fi Button is a supportive WordPress plugin that allows you to accept donations, tips, and support from your audience directly on your website, effectively turning your passion into income."
- [kofi]
Ko-fi Button [kofi] Shortcode
The Ko-fi Button shortcode enables the addition of a customizable button to your WordPress site. It fetches options like ‘text’, ‘color’, and ‘code’ from plugin settings. Depending on the ‘type’ attribute, it either returns a button or panel embed code.
Shortcode: [kofi]
Parameters
Here is a list of all possible kofi shortcode parameters and attributes:
text
– Defines the text of the ko-fi buttoncolor
– Sets the color of the ko-fi buttontype
– Determines if the shortcode will display a button or a panelcode
– Specifies the unique code of the coffee option
Examples and Usage
Basic example – A simple shortcode to display a Ko-fi button with default settings.
[kofi /]
Advanced examples
Display a Ko-fi button with custom text and color. This example allows you to personalize the button according to your website’s theme and messaging.
[kofi text="Support Me" color="#FF5F5F" /]
Display a Ko-fi panel instead of a button. This will show a larger, more detailed panel, including your Ko-fi code.
[kofi type="panel" code="YourKofiCode" /]
Display a Ko-fi button with all custom attributes. This is a comprehensive example that includes all available attributes.
[kofi text="Support Me" color="#FF5F5F" type="button" code="YourKofiCode" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [kofi]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'kofi', array( __CLASS__, 'kofi_shortcode' ) );
Shortcode PHP function:
function kofi_shortcode( $atts ) {
// Attributes.
$atts = shortcode_atts(
array(
'text' => self::get_plugin_option( 'coffee_text' ),
'color' => self::get_plugin_option( 'coffee_color' ),
'type' => 'button',
'code' => self::get_plugin_option( 'coffee_code' ),
),
$atts
);
// Return custom embed code.
if ( 'button' === $atts['type'] ) {
return self::get_button_embed_code( $atts );
} elseif ( 'panel' === $atts['type'] ) {
return self::get_panel_embed_code( $atts );
}
}
Code file location:
ko-fi-button/ko-fi-button/class-ko-fi.php
Conclusion
Now that you’ve learned how to embed the Ko-fi Button 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