Skip to content

Instantly share code, notes, and snippets.

@divimode-philipp
Last active September 30, 2022 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save divimode-philipp/1ca57ef2b5013e060effc8aa8af647cc to your computer and use it in GitHub Desktop.
Save divimode-philipp/1ca57ef2b5013e060effc8aa8af647cc to your computer and use it in GitHub Desktop.
Include Divi Areas in WordPress search results
<?php
/**
* How to use this snippet:
*
* 1. Click the "Download ZIP" button (top-right area)
* 2. Open wp-admin > Plugins > Add New
* 3. Click "Upload Plugin" and select the zip file
* 4. After uploading the zip file, activate the plugin
*
* ----------
*
* Plugin Name: Divi Areas Pro - Include in Search
* Description: Includes all Divi Areas in WordPress search results, even for for logged-out users.
* Plugin URI: https://gist.github.com/divimode-philipp/1ca57ef2b5013e060effc8aa8af647cc
* Version: 1.0.0
*/
/**
* By default, Divi Areas are excluded from WP search.
*
* This filter modifies the Divi Area configuration to allow WordPress
* to include Areas in search results.
*/
add_filter( 'divimode_register_post_type_divi-area', function ( $args = [] ) {
$args['exclude_from_search'] = false;
return $args;
} );
/**
* By default, only logged-in users who can edit a Divi Area can also
* preview it.
*
* This filter removes that limitation and allows every user to view
* all Divi Areas on a preview page.
*
* Without this filter, Divi Areas would be displayed in search results,
* but clicking on a search result entry would redirect the user to the
* websites home page instead of showing the Area contents.
*/
add_filter( 'divi_areas_can_preview_area', function ( $allowed = true, $area_id = 0 ) {
return true;
}, 10, 2 );
/**
* Next steps:
*
* Starting in Divi Areas Pro 3.2.0 you can customize the preview template
* that is used to display the Divi Area search result on the front-end.
*
* To do this, you need a child theme. Then copy the file
* "wp-content/plugins/divi-areas-pro/includes/builder/templates/single-divi-area.php"
* into your child theme folder, e.g. "wp-content/themes/divi-child/single-divi-area.php"
*
* Now you can modify the "single-divi-area.php" template inside your
* child theme - just ensure to keep the line "dap_cpt_the_preview()"!
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment