1. Home
  2. Docs
  3. Developer Info & API
  4. Add New Style Templates

Add New Style Templates

If you are making many style changes to your quiz, you may want to create your own style template which can then be used on all of your quizzes and surveys.

To do so, save all of your CSS to a CSS file. We can then use the “register_quiz_templates” function of the API to add the CSS file to our Style tab when editing our quizzes and surveys like in the example code below.

function qmn_register_my_templates() {
	global $mlwQuizMasterNext;
	$mlwQuizMasterNext->pluginHelper->register_quiz_template( 'My Template', 'my-quiz-template.css');
add_action( 'plugins_loaded', 'qmn_register_my_templates' );

The second parameter takes a path and filename to your CSS file. There are a few places that you can keep your CSS. First, let’s see the template enqueue code:

$registered_template = $mlwQuizMasterNext->pluginHelper->get_quiz_templates($qmn_quiz_options->theme_selected);
// Check direct file first, then check templates folder in plugin, then check templates file in theme.
// If all fails, then load custom styling instead
if ( $registered_template && file_exists( $registered_template["path"] ) ) {
	wp_enqueue_style( 'qmn_quiz_template', $registered_template["path"], array(), $mlwQuizMasterNext->version );
} elseif ( $registered_template && file_exists( plugin_dir_path(__FILE__).'../templates/'.$registered_template["path"] ) ) {
	wp_enqueue_style( 'qmn_quiz_template', plugins_url( '../templates/'.$registered_template["path"], __FILE__ ), array(), $mlwQuizMasterNext->version );
} elseif ( $registered_template && file_exists( get_stylesheet_directory_uri().'/templates/'.$registered_template["path"] ) ) {
	wp_enqueue_style( 'qmn_quiz_template', get_stylesheet_directory_uri().'/templates/'.$registered_template["path"], array(), $mlwQuizMasterNext->version );
} else {
	echo "<style type='text/css'>".$qmn_quiz_options->quiz_stye."</style>";

The first place the plugin looks is the path relative to the current directory. The second place it looks is inside the “templates” folder inside the plugin’s directory.

Lastly, it then checks for a “templates” folder inside the theme.

If the plugin cannot find any matching CSS file, it will load the contents of the text box found on the Style tab.