Created
August 10, 2018 00:50
-
-
Save justinswelch/220d8d1551920836535ce44c22011f89 to your computer and use it in GitHub Desktop.
Shortcode that displays a random saved BB layout on each page refresh.
This file contains hidden or 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 | |
| /** | |
| * Plugin Name: PXB - Random Beaver Layouts | |
| * Description: Show random saved layouts in BB with shortcode | |
| * Version: 1.0 | |
| * Author: Pixablaze | |
| * Author URI: https://www.pixablaze.com | |
| */ | |
| /*---------------------------------------------------------- | |
| Shortcode to display random layouts in Beaver Builder | |
| ------------------------------------------------------------ | |
| - Usage of shortcode: [bb_random_layouts ids="64, 67, 75"] | |
| - ids are the Beaver Builder saved template/row/module ids | |
| - insert into BB text editor module (or anywhere shortcodes work) | |
| -----------------------------------------------------------*/ | |
| function pxb_random_bb_layouts( $atts ) { | |
| $atts = ( shortcode_atts( [ 'ids' => null ], $atts ) ); | |
| $ids = explode( ",", $atts[ 'ids' ] ); | |
| if( ! is_array( $ids) ) { | |
| return false; | |
| } | |
| $bb_randomized_shortcode = sprintf( '[fl_builder_insert_layout id="%s"]', | |
| $ids[ array_rand( $ids ) ] | |
| ); | |
| return $bb_randomized_shortcode ; | |
| } | |
| add_shortcode( 'bb_random_layouts', 'pxb_random_bb_layouts' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @justinswelch, thanks for the code.
While it works on regular pages and posts, it for some reason doesn't work for Beaver Themer elements, in my case, on 404 page, it doesn't work.
It returns the code randomly and that's it, it doesn't run the code. Do you have any idea why?