Echo Knowledge Base Shortcodes

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

Before starting, here is an overview of the Echo Knowledge Base Plugin and the shortcodes it provides:

Plugin Icon
Knowledge Base for Documentation, FAQs with AI Assistance

"Knowledge Base for Documentation, FAQs with AI Assistance is a comprehensive WordPress plugin. It aids in creating, organizing, and managing online documentation and FAQs, with added AI assistance for efficiency."

★★★★★ (93) Active Installs: 10000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • [echo-kb-main-page]
  • [epkb-articles-index-directory]

Echo Knowledge Base [KB_MAIN_PAGE_SHORTCODE_NAME] Shortcode

The Echo Knowledge Base plugin shortcode is designed to output a knowledge base main page. It retrieves a KB configuration based on shortcode attributes and enqueues necessary scripts. If a page with the KB shortcode is missing, it adds it to the KB main pages.

Shortcode: [echo-kb-main-page]

Examples and Usage

Basic example – Displays the main knowledge base page using the shortcode. No parameters are needed in this case.

[echo-kb-main-page]

Advanced examples

Using the shortcode to display a specific knowledge base page by referencing the knowledge base ID. This allows you to display a specific knowledge base if you have multiple knowledge bases on your site.

[echo-kb-main-page id=2]

Using the shortcode to display a specific knowledge base page by referencing the knowledge base ID and a specific post within that knowledge base. This will display the main page of the knowledge base with the specified post highlighted.

[echo-kb-main-page id=2 post_id=15]

Please note that the actual shortcode name and parameters will depend on how the shortcode is registered in your WordPress installation. The examples above assume that the shortcode is registered as ‘echo-kb-main-page’.

PHP Function Code

In case you have difficulties debugging what causing issues with [echo-kb-main-page] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( self::KB_MAIN_PAGE_SHORTCODE_NAME, array( 'EPKB_Layouts_Setup', 'output_kb_page_shortcode' ) );

Shortcode PHP function:

function output_kb_page_shortcode( $shortcode_attributes ) {
        $kb_config = self::get_kb_configuration( $shortcode_attributes );
		
		do_action( 'epkb_enqueue_scripts', $kb_config['id'] );

		global $eckb_kb_id, $post;

        // add page with KB shortcode to KB Main Pages if missing
        if ( empty($eckb_kb_id) ) {

            $kb_main_pages = $kb_config['kb_main_pages'];
	        $query_post = empty($GLOBALS['wp_the_query']) ? null : $GLOBALS['wp_the_query']->get_queried_object();
			$post = empty( $query_post ) && ! empty( $post ) && $post instanceof WP_Post ? $post : $query_post;

	        // add missing post to main pages
	        if ( ! empty( $post->post_type ) && $post->post_type == 'page' && ! empty($post->ID) &&
		        is_array($kb_main_pages) && ! in_array($post->ID, array_keys($kb_main_pages)) && ! in_array($post->post_status, array('inherit', 'trash', 'auto-draft' )) ) {
		        $post_id = $post->ID;
		        $kb_main_pages[$post_id] = empty($post->post_title) ? '[KB Main Page]' : $post->post_title;
		        epkb_get_instance()->kb_config_obj->set_value( $kb_config['id'], 'kb_main_pages', $kb_main_pages );
	        }
        }

		return self:: output_main_page( $kb_config );
	}

Code file location:

echo-knowledge-base/echo-knowledge-base/includes/features/kbs/class-epkb-kb-handler.php

Echo Knowledge Base [epkb-articles-index-directory] Shortcode

The Echo Knowledge Base shortcode generates an indexed list of articles. It enqueues the necessary style, sets the title, and retrieves the relevant articles. If no articles are found, it displays a placeholder message. If articles are present, it creates a structured list with links to each article.

Shortcode: [epkb-articles-index-directory]

Parameters

Here is a list of all possible epkb-articles-index-directory shortcode parameters and attributes:

  • title – The title that will be displayed above the list of indexed articles.
  • kb_id – The unique identifier of the knowledge base to display articles from.

Examples and Usage

Basic example – Displaying the index of articles in a Knowledge Base without a title.

[epkb-articles-index-directory /]

This shortcode will output an index of all articles in the default Knowledge Base. If no title is provided, it will default to “Indexed Articles”.

Advanced examples

Displaying the index of articles in a specific Knowledge Base with a custom title.

[epkb-articles-index-directory title="My Custom Title" kb_id=2 /]

This shortcode will output an index of all articles in the Knowledge Base with the ID of 2. The title of the index will be “My Custom Title”.

Displaying the index of articles in a Knowledge Base using only the title attribute.

[epkb-articles-index-directory title="My Custom Title" /]

This shortcode will output an index of all articles in the default Knowledge Base. The title of the index will be “My Custom Title”.

PHP Function Code

In case you have difficulties debugging what causing issues with [epkb-articles-index-directory] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'epkb-articles-index-directory', array( $this, 'output_shortcode' ) );

Shortcode PHP function:

function output_shortcode( $attributes ) {
		global $eckb_kb_id;

		wp_enqueue_style( 'epkb-shortcodes' );

		// allows to adjust the widget title
		$title = empty($attributes['title']) ? '' : strip_tags( trim($attributes['title']) );
		$title = ( empty( $title ) ? esc_html__( 'Indexed Articles', 'echo-knowledge-base' ) : esc_html( $title ) );

		// get add-on configuration
		$kb_id = empty( $attributes['kb_id'] ) ? ( empty( $eckb_kb_id ) ? EPKB_KB_Config_DB::DEFAULT_KB_ID : $eckb_kb_id ) : $attributes['kb_id'];
		$kb_id = EPKB_Utilities::sanitize_int( $kb_id, EPKB_KB_Config_DB::DEFAULT_KB_ID );

		$indexed_articles_list = $this->get_indexed_articles_list( $kb_id );

		if ( empty( $indexed_articles_list ) ) {
			ob_start(); ?>
			<div id="epkb-article-index-dir-container">
				<div class="epkb-aid__body-container"><?php
					echo esc_html__( 'Articles coming Soon', 'echo-knowledge-base' ); ?>
					</div>
			</div><?php
			return ob_get_clean();
		}

		// DISPLAY INDEXED ARTICLES // TODO improve html, add correct classes and ids
		ob_start(); ?>
		<div id="epkb-article-index-dir-container">

            <div class="epkb-aid__header-container">
                <h2 class="epkb-aid__header__title" aria-label="<?php echo esc_html( $title ); ?>"><?php echo esc_html( $title ); ?></h2>
            </div>

            <div class="epkb-aid__body-container">
                <?php foreach ( $indexed_articles_list as $indexed_result ) { ?>

                    <section id="epkb-aid__section-<?php echo esc_html( $indexed_result['index'] ); ?>" class="epkb-aid__section-container"
                             role="contentinfo" aria-label="Article List for Letter <?php echo esc_html( $indexed_result['index'] ); ?>">

                        <div class="epkb-aid-section__header">
                            <div class="epkb-aid-section__header__title"><?php echo esc_html( $indexed_result['index'] ); ?></div>
                        </div>

                        <div class="epkb-aid-section__body">
                            <ul class="epkb-aid-section__body__list-container">  <?php
                                foreach ( $indexed_result['articles'] as $article_id => $article_title ) {
                                    $article_url = get_permalink( $article_id );
                                    if ( empty( $article_url ) || is_wp_error( $article_url ) ) {
                                        continue;
                                    }  ?>
                                    <li id="epkb-aid-article-<?php echo esc_html( $article_id ); ?>" class="epkb-aid-list__item">
                                        <a href="<?php echo esc_url( $article_url ); ?>">
                                            <span class="epkb-aid-list__item__icon">
                                                <span aria-hidden="true" class="epkbfa epkb-aid-article-icon ep_font_icon_document"></span>
                                            </span>
                                            <span class="epkb-aid-list__item__text"><?php echo esc_html( $article_title ); ?></span>
                                        </a>
                                    </li>  <?php
                                } ?>
                            </ul>
                        </div>

                    </section>

                <?php } ?>
            </div>

		</div>  <?php
		return ob_get_clean();
	}

Code file location:

echo-knowledge-base/echo-knowledge-base/includes/features/shortcodes/class-epkb-articles-index-shortcode.php

Conclusion

Now that you’ve learned how to embed the Echo Knowledge Base 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 *