Gwolle Guestbook Shortcodes

Below, you’ll find a detailed guide on how to add the Gwolle Guestbook 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 Gwolle Guestbook Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Gwolle Guestbook Plugin and the shortcodes it provides:

Plugin Icon
Gwolle Guestbook

"Gwolle Guestbook is a user-friendly, robust plugin for WordPress. It allows you to easily add a guestbook to your website, encouraging visitor interaction and feedback."

★★★★☆ (108) Active Installs: 30000+ Tested with: 6.3.2 PHP Version: 7.0
Included Shortcodes:
  • [gwolle_gb_widget]
  • [gwolle-gb]
  • [gwolle_gb_write]
  • [gwolle_gb_read]

Gwolle Guestbook [gwolle_gb_widget] Shortcode

The Gwolle Guestbook shortcode allows you to display recent guestbook entries on your website. It fetches the latest entries based on specified parameters like ‘book_id’, ‘num_entries’, and ‘num_words’. This shortcode enqueues the CSS for frontend styling, sets the widget title and parameters, and generates an HTML layout with guestbook entries. It uses filters for customization, allowing developers to modify the output.

Shortcode: [gwolle_gb_widget]

Parameters

Here is a list of all possible gwolle_gb_widget shortcode parameters and attributes:

  • book_id – Identifier for the specific guestbook to display entries from.
  • num_entries – Number of guestbook entries to display.
  • num_words – Maximum number of words for each guestbook entry preview.

Examples and Usage

Basic example – Display the latest 5 entries from the guestbook with a maximum of 10 words per entry.

[gwolle_gb_widget book_id=0 num_entries=5 num_words=10 /]

Advanced examples

Display the latest 10 entries from a specific guestbook (book_id=2) with a maximum of 15 words per entry.

[gwolle_gb_widget book_id=2 num_entries=10 num_words=15 /]

Use the shortcode to display the latest entries from the guestbook of the current post. The number of entries and words per entry are set to their default values (5 entries, 10 words).

[gwolle_gb_widget book_id="post_id" /]

Display the latest 7 entries from the guestbook with a maximum of 20 words per entry. Here, the book_id is set to its default value (0), which means that entries from all guestbooks will be shown.

[gwolle_gb_widget num_entries=7 num_words=20 /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'gwolle_gb_widget', 'get_gwolle_gb_shortcode_widget' );

Shortcode PHP function:

function get_gwolle_gb_shortcode_widget( $atts ) {

	$shortcode_atts = shortcode_atts( array(
		'book_id'     => 0,
		'num_entries' => 5,
		'num_words'   => 10,
	), $atts );

	if ( $shortcode_atts['book_id'] === 'post_id' ) {
		$shortcode_atts['book_id'] = get_the_ID();
	}

	// Load Frontend CSS in Footer, only when it's active.
	wp_enqueue_style('gwolle_gb_frontend_css');

	$widget_title = esc_html__('Guestbook', 'gwolle-gb');
	$book_id      = $shortcode_atts['book_id'];
	$num_entries  = $shortcode_atts['num_entries'];
	$num_words    = $shortcode_atts['num_words'];
	$postid       = 0;

	$widget_class = 'gwolle_gb_widget gwolle-gb-widget';
	$widget_class = apply_filters( 'gwolle_gb_widget_list_class', $widget_class );
	$widget_item_class = 'gwolle_gb_widget gwolle-gb-widget';
	$widget_item_class = apply_filters( 'gwolle_gb_widget_item_class', $widget_item_class );


	$widget_html = '
				<div class="gwolle_gb_widget gwolle-gb-widget">';
	$widget_html .= apply_filters('widget_title', $widget_title);

	$widget_html .= '
					<ul class="' . $widget_class . '">';

	// Get the latest $num_entries guestbook entries
	$entries = gwolle_gb_get_entries(
		array(
			'num_entries'   => $num_entries,
			'checked'       => 'checked',
			'trash'         => 'notrash',
			'spam'          => 'nospam',
			'book_id'       => $book_id,
			)
		);

	if ( is_array( $entries ) && ! empty( $entries ) ) {
		foreach ( $entries as $entry ) {
			$widget_html .= '
						<li class="' . $widget_item_class . '">';

			$widget_html .= '
							<article>';

			// Use this filter to just add something
			$widget_html .= apply_filters( 'gwolle_gb_entry_widget_add_before', '', $entry );

			$widget_html .= '
								<span class="gb-author-name">' . $entry->get_author_name() . '</span>';
			$widget_html .= ' / ';
			$widget_html .= '
								<span class="gb-date">' . date_i18n( get_option('date_format'), $entry->get_datetime() ) . '</span>';
			$widget_html .= ':<br />';

			$entry_content = gwolle_gb_get_excerpt( gwolle_gb_bbcode_strip($entry->get_content()), $num_words );
			if ( get_option('gwolle_gb-showSmilies', 'true') === 'true' ) {
				$entry_content = convert_smilies($entry_content);
			}
			$widget_html .= '
								<span class="gb-entry-content">' . $entry_content;

			// Use this filter to just add something
			$widget_html .= apply_filters( 'gwolle_gb_entry_widget_add_content', '', $entry );

			$widget_html .= '</span>';

			// Use this filter to just add something
			$widget_html .= apply_filters( 'gwolle_gb_entry_widget_add_after', '', $entry );

			$widget_html .= '
							</article>';

			$widget_html .= '
						</li>';
		}
	}

	$widget_html .= '
					</ul>';
	$widget_html .= '
				</div>';

	// Add a filter for the entries, so devs can add or remove parts.
	$widget_html = apply_filters( 'gwolle_gb_widget', $widget_html);

	return $widget_html;
}

Code file location:

gwolle-gb/gwolle-gb/frontend/gb-shortcode-widget.php

Gwolle Guestbook [gwolle-gb] Shortcode

The ‘gwolle-gb’ shortcode from the Gwolle Guestbook plugin displays a guestbook on your WordPress site. It allows customization of the book_id, entry_id, and the number of entries displayed. This shortcode also enqueues the necessary CSS and JavaScript files, ensuring the guestbook’s proper functionality and appearance. It dynamically updates the book_id to the current post ID, allowing for seamless integration into your content.

Shortcode: [gwolle-gb]

Parameters

Here is a list of all possible gwolle-gb shortcode parameters and attributes:

  • book_id – Specifies the ID of the guestbook to display.
  • entry_id – Determines a specific guestbook entry to show.
  • button – Controls whether to display a submission button.
  • num_entries – Sets the number of guestbook entries per page.

Examples and Usage

Basic example – Utilizes the gwolle-gb shortcode to display a guestbook with the default settings.

[gwolle-gb /]

Advanced examples

Display a specific guestbook by using the ‘book_id’ attribute. In this case, it will display the guestbook with an ID of 2.

[gwolle-gb book_id=2 /]

Display a specific entry from a guestbook by using the ‘entry_id’ attribute. This will display the entry with an ID of 3 from the default guestbook.

[gwolle-gb entry_id=3 /]

Control the number of entries displayed per page using the ‘num_entries’ attribute. This will display 10 entries per page from the default guestbook.

[gwolle-gb num_entries=10 /]

Hide the ‘Write new entry’ button by setting the ‘button’ attribute to ‘false’. This will display the default guestbook without the ‘Write new entry’ button.

[gwolle-gb button=false /]

Combine multiple attributes to further customize the guestbook display. This will display 5 entries per page from the guestbook with an ID of 2, without the ‘Write new entry’ button.

[gwolle-gb book_id=2 num_entries=5 button=false /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'gwolle-gb', 'get_gwolle_gb' ); // deprecated, do not use dashes in Shortcode API

Shortcode PHP function:

function get_gwolle_gb( $atts ) {

	$shortcode = 'gwolle_gb';

	$num_entries = (int) get_option('gwolle_gb-entriesPerPage', 20);
	$num_entries = (int) apply_filters( 'gwolle_gb_read_num_entries', $num_entries, $atts );

	$shortcode_atts = shortcode_atts( array(
		'book_id'     => 1,
		'entry_id'    => 0,
		'button'      => 'true', // default when main shortcode is used.
		'num_entries' => $num_entries,
	), $atts );

	if ( $shortcode_atts['book_id'] === 'post_id' ) {
		$shortcode_atts['book_id'] = get_the_ID();
	}

	if ( is_singular() && is_main_query() && ! is_admin() ) {
		$id = get_the_ID();
		update_post_meta( $id, 'gwolle_gb_book_id', $shortcode_atts['book_id'] );
	}

	// Load Frontend CSS in Footer, only when it's active
	wp_enqueue_style('gwolle_gb_frontend_css');
	//wp_enqueue_script('jquery');
	wp_enqueue_script('gwolle_gb_frontend_js');


	// Define $output
	$output = '<div class="gwolle-gb">';

	// Add the form
	$output .= gwolle_gb_frontend_write( $shortcode_atts, $shortcode );

	// Add the list of entries to show
	$output .= gwolle_gb_frontend_read( $shortcode_atts, $shortcode );

	$output .= '</div>';

	return $output;
}

Code file location:

gwolle-gb/gwolle-gb/frontend/gb-shortcodes.php

Gwolle Guestbook [gwolle_gb_write] Shortcode

The ‘gwolle_gb_write’ shortcode from the Gwolle Guestbook plugin allows users to add a guestbook entry form to a post or page. It accepts parameters for ‘book_id’, ‘entry_id’, and ‘button’. It dynamically sets the ‘book_id’ to the current post ID if ‘post_id’ is provided. The shortcode also updates the post meta with the ‘book_id’ if it’s the main query on a singular page. The frontend CSS and JavaScript are enqueued for the form, which is appended to the output wrapped in a ‘gwolle-gb’ div.

Shortcode: [gwolle_gb_write]

Parameters

Here is a list of all possible gwolle_gb_write shortcode parameters and attributes:

  • book_id – Identifier of the guestbook, default is 1
  • entry_id – Identifier of the guestbook entry, default is 0
  • button – Determines if button is shown, default is ‘false’

Examples and Usage

Basic example – A simple implementation of the gwolle_gb_write shortcode. The book_id is set to 1 and the button attribute is set to false, meaning the button won’t be displayed.

[gwolle_gb_write book_id=1 button=false /]

Advanced examples

Here, we’re using the shortcode to display a specific guestbook entry by referencing its ID. The book_id is set to 1 and the entry_id is set to the specific ID of the entry we want to display.

[gwolle_gb_write book_id=1 entry_id=15 /]

In this example, we’re using the shortcode to display a guestbook form for a specific post. The book_id is set to ‘post_id’, which means the form will be associated with the ID of the current post.

[gwolle_gb_write book_id=post_id /]

This is an advanced usage of the shortcode where we display a guestbook form for a specific post and also display the button. The book_id is set to ‘post_id’ and the button attribute is set to true.

[gwolle_gb_write book_id=post_id button=true /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'gwolle_gb_write', 'get_gwolle_gb_write' );

Shortcode PHP function:

function get_gwolle_gb_write( $atts ) {

	$shortcode = 'gwolle_gb_write';

	$shortcode_atts = shortcode_atts( array(
		'book_id'  => 1,
		'entry_id' => 0,
		'button'   => 'false', // default when only the write shortcode is used.
	), $atts );

	if ( $shortcode_atts['book_id'] === 'post_id' ) {
		$shortcode_atts['book_id'] = get_the_ID();
	}

	if ( is_singular() && is_main_query() && ! is_admin() ) {
		$id = get_the_ID();
		update_post_meta( $id, 'gwolle_gb_book_id', $shortcode_atts['book_id'] );
	}

	// Load Frontend CSS in Footer, only when it's active
	wp_enqueue_style('gwolle_gb_frontend_css');
	//wp_enqueue_script('jquery');
	wp_enqueue_script('gwolle_gb_frontend_js');


	// Define $output
	$output = '<div class="gwolle-gb">';

	// Add the form
	$output .= gwolle_gb_frontend_write( $shortcode_atts, $shortcode );

	$output .= '</div>';

	return $output;
}

Code file location:

gwolle-gb/gwolle-gb/frontend/gb-shortcodes.php

Gwolle Guestbook [gwolle_gb_read] Shortcode

The Gwolle Guestbook shortcode is a versatile tool that displays guestbook entries on your WordPress site. This shortcode fetches entries based on the specified ‘book_id’ and ‘entry_id’. It allows you to control the number of entries shown per page, defaulting to 20. The shortcode also supports dynamic book_id assignment using the ‘post_id’ of the current page. Moreover, it enqueues the necessary CSS and JavaScript files for frontend display, ensuring a seamless user experience. The output is a neatly formatted list of guestbook entries enclosed in a ‘gwolle-gb’ div.

Shortcode: [gwolle_gb_read]

Parameters

Here is a list of all possible gwolle_gb_read shortcode parameters and attributes:

  • book_id – Identifier for the specific guestbook to display.
  • entry_id – Specific guestbook entry to show.
  • num_entries – Number of guestbook entries to display per page.

Examples and Usage

Basic example – The following shortcode will display the guestbook entries from the first book, showing 20 entries per page (default).

[gwolle_gb_read book_id=1 /]

Advanced examples

Displaying guestbook entries from a specific book (book_id=2) and limiting the number of entries per page to 10 instead of the default 20.

[gwolle_gb_read book_id=2 num_entries=10 /]

Using the shortcode to display guestbook entries from the same post where it is placed (book_id=’post_id’).

[gwolle_gb_read book_id='post_id' /]

Displaying a specific entry (entry_id=3) from a specific book (book_id=2).

[gwolle_gb_read book_id=2 entry_id=3 /]

Please note that ‘book_id’ refers to the ID of the guestbook and ‘entry_id’ refers to the ID of the specific entry within the guestbook. The ‘num_entries’ attribute determines the number of entries displayed per page.

PHP Function Code

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

Shortcode line:

add_shortcode( 'gwolle_gb_read', 'get_gwolle_gb_read' );

Shortcode PHP function:

function get_gwolle_gb_read( $atts ) {

	$shortcode = 'gwolle_gb_read';

	$num_entries = (int) get_option('gwolle_gb-entriesPerPage', 20);
	$num_entries = (int) apply_filters( 'gwolle_gb_read_num_entries', $num_entries, $atts );

	$shortcode_atts = shortcode_atts( array(
		'book_id'  => 1,
		'entry_id' => 0,
		'num_entries' => $num_entries,
	), $atts );

	if ( $shortcode_atts['book_id'] === 'post_id' ) {
		$shortcode_atts['book_id'] = get_the_ID();
	}
	if ( is_singular() && is_main_query() && ! is_admin() ) {
		$id = get_the_ID();
		update_post_meta( $id, 'gwolle_gb_book_id', $shortcode_atts['book_id'] );
	}

	// Load Frontend CSS in Footer, only when it's active
	wp_enqueue_style('gwolle_gb_frontend_css');
	//wp_enqueue_script('jquery');
	wp_enqueue_script('gwolle_gb_frontend_js');


	// Define $output
	$output = '<div class="gwolle-gb">';

	// Add the list of entries to show
	$output .= gwolle_gb_frontend_read( $shortcode_atts, $shortcode );

	$output .= '</div>';

	return $output;
}

Code file location:

gwolle-gb/gwolle-gb/frontend/gb-shortcodes.php

Conclusion

Now that you’ve learned how to embed the Gwolle Guestbook 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.

Comments

Leave a Reply

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