How to Create a Simple WordPress FAQ Plugin

A “Typically Requested Questions” half is an efficient machine to offer your prospects the exact reply to their questions. That’s turning into very popular. Nevertheless pretty typically FAQs are built-in inside premium theme, nonetheless what about free themes? This is a tutorial to create a simple WordPress FAQ Plugin that will work with any theme. This tutorial may be defending solely fundamentals steps to have the ability to then customise the FAQ half and make it your particular person!

Step 1: Create The Plugin

To begin out, create a model new folder in your “wp-content/plugins” folder known as “rc-faq”. Then create a model new file inside this folder known as “rc-faq.php” and place this code:

Plugin Determine: RC Faq
Plugin URL:
Description: A simple FAQ plugin
Mannequin: 1.0
Creator: Remi Corson
Creator URI:
Contributors: corsonr

Step 2: Register The FAQ Personalized Put up Sort

We now should register a personalized publish kind. For those who’re not accustomed to this half, it’s possible you’ll have a look to the Codex.

 * Register CPT rc_faq
carry out rc_faq_setup_post_types() {

	$faq_labels =  apply_filters( 'rc_faq_labels', array(
		'determine'                => 'FAQs',
		'singular_name'       => 'FAQ',
		'add_new'             => __('Add New', 'rc_faq'),
		'add_new_item'        => __('Add New FAQ', 'rc_faq'),
		'edit_item'           => __('Edit FAQ', 'rc_faq'),
		'new_item'            => __('New FAQ', 'rc_faq'),
		'all_items'           => __('All FAQs', 'rc_faq'),
		'view_item'           => __('View FAQ', 'rc_faq'),
		'search_items'        => __('Search FAQs', 'rc_faq'),
		'not_found'           => __('No FAQs found', 'rc_faq'),
		'not_found_in_trash'  => __('No FAQs current in Trash', 'rc_faq'),
		'parent_item_colon'   => '',
		'menu_name'           => __('FAQs', 'rc_faq'),
		'exclude_from_search' => true
	) );

	$faq_args = array(
		'labels' 			=> $faq_labels,
		'public' 			=> true,
		'publicly_queryable'=> true,
		'show_ui' 			=> true,
		'show_in_menu' 		=> true,
		'query_var' 		=> true,
		'capability_type' 	=> 'publish',
		'has_archive' 		=> false,
		'hierarchical' 		=> false,
		'helps' 			=> apply_filters('rc_faq_supports', array( 'title', 'editor' ) ),
	register_post_type( 'rc_faq', apply_filters( 'rc_faq_post_type_args', $faq_args ) );


add_action('init', 'rc_faq_setup_post_types');

Please remember utilizing the apply_filters() carry out. This allows you to modify help and arguments with out modifying the plugin itself.

Step 3: Create A Shortcode To Present FAQs

This step is the place we’ll create a simple shortcode with only one parameter that will current the FAQs to your buyer. The thought is to guidelines solely FAQs title and present options solely when the title is clicked.

The shortcode may have a novel “prohibit” parameter that defines the number of devices to point. In actual fact it’s possible you’ll add your add private attributes: order, order by, and so forth…

Moreover, this shortcode embody a javascript snippet included immediately all through the shortcode itself so that the javascript solely plenty whenever you’re on the net web page having the shortcode.

Lastly we disguise by default the FAQ content material materials and present it solely when its title is clicked.

 * Add [rc_faq limit="-1"] shortcode
carry out rc_faq_shortcode( $atts, $content material materials = null ) {
		"prohibit" => ''
	), $atts ) );
	// Define prohibit
	if ( $prohibit ) { 
		$posts_per_page = $prohibit; 
	} else {
		$posts_per_page = '-1';

	// Create the Query
	$post_type = 'rc_faq';
	$orderby   = 'menu_order';
	$order     = 'ASC';
	$query = new WP_Query( array ( 
		'post_type'      => $post_type,
		'posts_per_page' => $posts_per_page,
		'orderby'        => $orderby, 
		'order'          => $order,
		'no_found_rows'  => 1
	) );
	//Get publish kind rely
	$post_count = $query->post_count;
	$i = 1;
	// Exhibits FAQ knowledge
	if ( $post_count > 0) :
		// Loop
		whereas ($query->have_posts()) : $query->the_post(); ?>
		<h3 class="rc_faq_title"><a href="#" onclick="rc_faq_toggle('rc_faq_<?php echo get_the_ID(); ?>');"><?php the_title(); ?></a></h3>
		<p id="rc_faq_<?php echo get_the_ID(); ?>" kind="present: none;"><?php echo get_the_content(); ?></p>

	// Reset query to forestall conflicts
	wp_reset_query(); ?>

	<script kind="textual content material/javascript">
		carry out rc_faq_toggle(id) {
			var e = doc.getElementById(id);
			e.kind.present = ((e.kind.present!='none') ? 'none' : 'block');
	return ob_get_clean();


add_shortcode( "rc_faq", "rc_faq_shortcode" ); ?>

And that’s it !

The Final Finish consequence

Proper right here is the last word consequence throughout the administration:

WordPress FAQ Plugin Admin Panel

And on the company’ aspect:

WordPress FAQ Plugin UI

Download The WPSaviour App Now

Pay in your preferred currency
Indian rupee