Last active
August 29, 2015 14:06
-
-
Save mrwweb/fd2adace8679b6bfa711 to your computer and use it in GitHub Desktop.
Example of fpw_widget_templates filter in Feature a Page Widget 2.0. Allows remove of default layouts, "registering" of custom layouts, or setting one layout for all widget instances.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* remove a default template | |
* | |
* default templates are: big, banner, wrapped | |
* | |
* this example removes the "Big Image" template | |
* | |
* @param $templates array slug => label pairs of templates | |
*/ | |
function fpw_remove_widget_template( $templates ) { | |
unset( $templates['big'] ); | |
return $templates; | |
} | |
add_filter( 'fpw_widget_templates', 'fpw_remove_widget_template' ); | |
/** | |
* add a custom template | |
* | |
* In addition to this filter, you must create a file named my_new_template.php in a /fpw2_views/ folder in the active child or parent theme | |
* | |
* @param $templates array slug => label pairs of templates | |
*/ | |
function fpw_add_widget_template( $templates ) { | |
$templates['my_new_template'] = __( 'My New Template', 'your-text-domain' ); | |
return $templates; | |
} | |
add_filter( 'fpw_widget_templates', 'fpw_add_widget_template' ); | |
/** | |
* add one layout for all widgets (& remove Layout setting) | |
* | |
* Example sets widget to always use the "Banner" layout | |
* | |
* @param $templates array slug => label pairs of templates | |
*/ | |
function fpw_set_widget_template() { | |
$template = array( 'banner' => 'Banner Image' ); // note array length = 1 | |
return $template; | |
} | |
add_filter( 'fpw_widget_templates', 'fpw_set_widget_template' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment