Forked from divimode-philipp/divi-areas-in-search-results.php
Created
September 30, 2022 08:35
-
-
Save stracker-phil/85d8aa5ee98a42377e46b33ee4dac3f9 to your computer and use it in GitHub Desktop.
Include Divi Areas in WordPress search results
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 | |
/** | |
* 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