Finally, use Widgets to maintain and customize your 404 Error and Search Not Found pages in Genesis Framework and Child Themes.
We all know that sometimes 404 Errors happen on our sites. And sometimes users search but get no results. I believe it’s better to serve users some highly customized and maintained pages/content areas for these cases. What better to do that with Widgets in WordPress? — In my opinion Genesis Framework could improve here so that’s why I just made this little plugin to FINALLY have these two cases maintainable EASILY via your widgets admin. Just place in a search widget, your last blog posts, an image widget, some explanation via text widget, some galleries… You got it. The possibilities are endless. Finally.
Just a great helper tool for Genesis Child Themes!
Please note: The plugin requires the Genesis Framework, a paid premium product released by StudioPress/ WPEngine, Inc. (via studiopress.com)
genesis_search_text
and genesis_search_button_text
for default strings :-).en_US
) – always includedde_DE
) – always includedde_DE_formal
) – always includedes_ES
) – user-submitted – currently 37% complete for v1.5.0.pot
file (genesis-widgetized-notfound.pot
) for translators is also always included 🙂Enjoy using Genesis Widgetized Not Found & 404? Please consider making a donation to support the project’s continued development.
I always wanted the 404 and search not found content easily customizeable! The standard messages like “Sorry, no posts matched your criteria.” are a shame and lame user experience. Widgets in WordPress are powerful and allow for adding really diverse and custom stuff. So, when building my “Autobahn” child theme for Genesis I really came across this idea and technique. I also implemented it in a lot of my client projects. Now I am really happy to represent this tool in form of a plugin to make more webmasters and especially users/visitors really happy – and help them stay longer on your site!
manage_options
and edit_theme_options
who is logged-ingenesis widgetized not found
), or extract the ZIP file and drop the contents in the wp-content/plugins/
directory of your WordPress installation.Two additional Widget areas - here with some example widgets placed in
Live site: displaying 404 Page - widgetized now! (Demo: Genesis Sample 2.6.0)
Live site: displaying here the "Search not found" page (Demo: Genesis Sample 2.6.0)
Widgets in Customizer with Live Preview: setup the 404 Error Page Widget area (Demo: Genesis Sample 2.6.0)
The plugin's own search widget called "Genesis - Search Form" with way more options than the WordPress core search widget!
The lugin's optional Shortcodes in action for a page
Live site: Shortcode from test page in action (Demo: Genesis Sample 2.6.0)
Submenu on Genesis Settings - quick access to setup
The plugin's help tab on the Widgets admin page with additional info
Plugins page entry with Quick Jump Links for setup, preview/ testing
For the 404 error (“Page not found”) the proper 404
HTTP status code gets delivered. This is completely done via Genesis itself, NOT by this plugin. This plugin “only” tweaks the content that is rendered on the 404 page in the browser. Everything else is done by Genesis. This is also how it should be.
You can (bulk) check the status yourself for any URL on online services like these:
You can use my “Genesis Layout Extras” plugin for that, which has an option for the 404 case built in. Or you can also use my built in helper function and add this little line to your functions.php
of your child theme (backup file before!) or to the “Custom Function” section of Prose Child Theme 1.5+:
/** Genesis Widgetized NotFound: 404 Error Page - Full-Width Layout */ add_action( 'genesis_meta', '__gwnf_layout_404_full_width' );
You can use my “Genesis Layout Extras” plugin for that, which has an option for the search case built in. — Or you can also use my built in helper function and add this little line to your functions.php
of your child theme (backup file before!) or to the “Custom Functions” section of Prose Child Theme 1.5+:
/** Genesis Widgetized NotFound: Search not found Page - Full-Width Layout */ add_action( 'genesis_meta', '__gwnf_layout_searchnotfound_full_width' );
Note: The above code is restricted to the case when NO search results are found! It doesn’t effect your search results display IF THERE ARE any results!
It’s all done via your child theme. Maybe you need to add an “!important” to some CSS rules here and there… For more even better styling I included some IDs and classes:
#gwnf-404-area
.gwnf-404
— which allows to set some common styles for all widgets in this area#gwnf-notfound-area
.gwnf-notfound
— which allows to set some common styles for all widgets in this areaNote, WordPress itself additionally adds body classes in the 404 case and the search not found case. So you can also use these classes: .error404
and .search-no-results
If that’s still not enough, you can even enqueue your own style, an action hook is included for that: gwnf_load_styles
— This hook fires within the WordPress action hook wp_enqueue_scripts
just after properly enqueueing the plugin’s styles and only if at least one of both widgets is active, so it’s fully conditional!
Of course, it’s possible! Just add the following constant to your child theme’s functions.php
file or to a functionality plugin:
/** Genesis Widgetized Not Found & 404: Remove Widgets Shortcode Support */ define( 'GWNF_NO_WIDGETS_SHORTCODE', TRUE );
Some webmasters could need this for security reasons regarding their stuff members or for whatever other reasons… :).
(1) Parameters for [gwnf-widget-area]
Shortcode:
area
— ID of the Widget area (Sidebar) (default: none, empty)404
OR notfound
OR bbpress-notfound
(2) Parameters for [gwnf-search]
Shortcode:
search_text
— Search placeholder text (default: Search this website
)button_text
— HTML wrapper tag (default: Search
)form_label
— Additional label before the search form (default: none, empty)wrapper
— HTML wrapper tag (default: Latest update date:
)class
— Additional custom CSS class for the wrapper (default: none, empty)post_type
— Optional setup post type(s) for search (default: none, empty – i.e., WordPress default search behavior!)Of course, that’s possible! Just add the following constant to your child theme’s functions.php
file or to a functionality plugin:
/** Genesis Widgetized Not Found & 404: Remove Shortcode Features */ define( 'GWNF_SHORTCODE_FEATURES', TRUE );
Of course, that’s possible – very easily :). Just add the following line of code to your child theme’s functions.php
file or a functionality plugin:
/** * Genesis Widgetized Not Found & 404: * Remove bbPress Widgetized Content Area on "not found" */ add_filter( 'gwnf_filter_bbpress_noresults_widgetized', '__return_false' );
I’ve just included some filters for that – if ever needed (i.e. for clients, branding purposes etc.), you can use these filters:
gwnf/filter/widget_areas/404/title – default value: “404 Error Page”
gwnf/filter/widget_areas/404/description – default value: “This is the widget area of the 404 Not Found Error Page.”
gwnf/filter/widget_areas/notfound/title – default value: “Search Not Found”
gwnf/filter/widget_areas/notfound/description – default value: “This is the widget area of the search not found content section.”
gwnf_filter_notfound_default – default value: “Sorry, no content matched your criteria. Try a different search?”
Example code for changing one of these filters:
add_filter( 'gwnf/filter/widget_areas/404/title', 'custom_404_widget_title' ); /** * Genesis Widgetized NotFound: Custom 404 Widget Title */ function custom_404_widget_title() { return __( 'Custom Error Page', 'your-child-theme-textdomain' ); }
Final note: I DON’T recommend to add customization code snippets to your child theme’s functions.php
file! Please use a functionality plugin instead! In general you should not abusing the functions.php for plugin-specific stuff. And you are then also more independent from child theme changes etc. If you don’t know how to create such a plugin yourself just use one of my recommended ‘Code Snippets’ plugins. Read & bookmark these Sites:
All the custom & branding stuff code above can also be found as a Gist on GitHub: https://gist.github.com/deckerweb/2473125 (you can also add your questions/ feedback there 🙂
(1) In general: You may use it for “global” widgets.
(2) Usage with the “WPML” plugin:
Widgets can be translated with their “String Translation” component – this is much easier than adding complex information/instructions to the 404 error or search not found pages for a lot of languages…
You can use the awesome “Widget Options” or “Widget Logic” plugins (or similar ones) and add additional paramaters, mostly conditional stuff like is_home()
in conjunction with is_language( 'de' )
etc. This way widget usage on a per-language basis is possible. Or you place in the WPML language codes like ICL_LANGUAGE_CODE == 'de'
for German language. Fore more info on that see their blog post: http://wpml.org/2011/03/howto-display-different-widgets-per-language/
With the following language detection code you are now able to make conditional statements, in the same way other WordPress conditional functions work, like is_single()
, is_home()
etc.:
if ( ! function_exists( 'is_language' ) ) : /** * WPML: Conditional Switching Languages * * @author David Decker - DECKERWEB * @link https://twitter.com/deckerweb * * @global mixed $GLOBALS[ 'sitepress' ] */ function is_language( $current_lang ) { if ( $current_lang == $GLOBALS[ 'sitepress' ]->get_current_language() ) { return TRUE; } } // end function endif;
Note: Be careful with the function name ‘is_language’ – this only works if there’s no other function in your install with that name! If it’s already taken (very rare case though), then just add a prefix like my_custom_is_language()
.
–> You now can use conditionals like that:
if ( is_language( 'de' ) ) { // do something for German language... } elseif ( is_language( 'es' ) ) { // do something for Spanish language... }
/wp-content/languages/genesis-widgetized-notfound/
(just create this folder) – This enables you to use fully custom translations that won’t be overridden on plugin updates. Also, complete custom English wording is possible with that as well, just use a language file like genesis-widgetized-notfound-en_US.mo/.po
to achieve that (for creating one see the following tools).Easy WordPress.org plugin translation platform with GlotPress platform:Translate “Genesis Widgetized Not Found & 404″…
Note: All my plugins are internationalized/ translateable by default. This is very important for all users worldwide. So please contribute your language to the plugin to make it even more useful. For translating and validating I recommend the awesome “Poedit Editor”, which works fine on Windows, macOS and Linux.
.pot
file plus all German translations (formal, informal) and language packs.pot
file plus all German translations (formal, informal) and language packscomposer.json
file to the plugin’s root folder – this is great for developers using ComposerREADME.md
file for plugin’s GitHub.com repository to make it more readable there.pot
file for translators, plus German translations[gwnf-search]
for displaying a configurable search for anywhere you like 🙂 — conditionally with full support for HTMTL5 & Genesis 2.0.0+ if in use.[gwnf-widget-area]
for displaying any of the plugin’s 3 Widget areas (if active) into Shortcode aware content areas.gwnf-styles.min.css
(gwnf-html5-styles.min.css
) is the minified default version, plus, gwnf-styles.css
(gwnf-html5-styles.css
) is now the development version. If WP_DEBUG
or SCRIPT_DEBUG
constants are true
, the dev styles will be loaded. This makes development/ customizing & debugging a lot easier! 🙂gwnf-styles.dev.css
and is still packaged).gwnf_load_styles
if you ever need to properly enqueue your own stylesheet for the edge cases… (Also see FAQ here).