Ko-fi Button Shortcode

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:

Plugin Icon
Ko-fi Button

"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."

★★★★★ (1) Active Installs: 5000+ Tested with: 6.2.3 PHP Version: 5.6
Included Shortcodes:
  • [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 button
  • color – Sets the color of the ko-fi button
  • type – Determines if the shortcode will display a button or a panel
  • code – 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.

Comments

Leave a Reply

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