Below, you’ll find a detailed guide on how to add the Modula Best Grid Gallery Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Modula Best Grid Gallery Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Modula Best Grid Gallery Plugin and the shortcodes it provides:
"Modula Image Gallery is a customizable WordPress gallery plugin, perfect for creating stunning image grids. With its user-friendly interface, design galleries with ease. Ideal for showcasing visual content."
- [modula]
- [modula-make-money]
Modula [modula] Shortcode
The Modula Best Grid Gallery shortcode is designed to handle and display a gallery. It starts by checking if the gallery ID exists and returns an error if not found. The shortcode fetches gallery settings and images, shuffles them if the option is enabled, and returns an error if settings or images are not found. It enqueues necessary scripts and styles, generates gallery CSS, and returns the gallery HTML.
Shortcode: [modula]
Parameters
Here is a list of all possible modula shortcode parameters and attributes:
id
– The unique identifier of the gallery.align
– Sets the alignment of the gallery.
Examples and Usage
Basic example – Display a gallery by referencing its ID.
[modula id=1 /]
Advanced examples
Display a gallery with a specific alignment. Here, the gallery will align to the right.
[modula id=1 align="right" /]
Display a gallery with a unique identifier. This could be useful in cases where you want to target a specific gallery with CSS or JavaScript.
[modula id=1 uniq_id="my_unique_gallery" /]
Display a gallery and specify the post status. In this example, the gallery will only display if the post status is “publish”.
[modula id=1 post_status="publish" /]
Please note that the actual shortcode parameters may vary depending on the Modula plugin settings and the specific implementation of the gallery_shortcode_handler function in your WordPress theme.
PHP Function Code
In case you have difficulties debugging what causing issues with [modula]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'modula', array( $this, 'gallery_shortcode_handler' ) );
Shortcode PHP function:
function gallery_shortcode_handler( $atts ) {
$default_atts = array(
'id' => false,
'align' => '',
);
$atts = wp_parse_args( $atts, $default_atts );
if ( ! $atts['id'] ) {
return esc_html__( 'Gallery not found.', 'modula-best-grid-gallery' );
}
$script_manager = Modula_Script_Manager::get_instance();
/* Generate uniq id for this gallery */
$gallery_id = 'jtg-' . $atts['id'];
// Check if is an old Modula post or new.
$gallery = get_post( $atts['id'] );
if ( null === $gallery || 'private' === $gallery->post_status && ! is_user_logged_in() ) {
return;
}
if ( 'modula-gallery' != get_post_type( $gallery ) ) {
$gallery_posts = get_posts( array(
'post_type' => 'modula-gallery',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'modula-id',
'value' => $atts['id'],
'compare' => '=',
),
),
) );
if ( empty( $gallery_posts ) ) {
return esc_html__( 'Gallery not found.', 'modula-best-grid-gallery' );
}
$atts['id'] = $gallery_posts[0]->ID;
}
/* Get gallery settings */
$settings = apply_filters('modula_backwards_compatibility_front',get_post_meta( $atts['id'], 'modula-settings', true ));
$default = Modula_CPT_Fields_Helper::get_defaults();
// Check "grid_type" before parsing and unset so defaults could be used.
if ( isset( $settings['type'] ) && 'grid' === $settings['type'] && empty( $settings['grid_type'] ) ) {
unset( $settings['grid_type'] );
}
$settings = wp_parse_args( $settings, $default );
$type = 'creative-gallery';
if ( isset( $settings['type'] ) ) {
$type = $settings['type'];
}else{
$settings['type'] = 'creative-gallery';
}
$pre_gallery_html = apply_filters( 'modula_pre_output_filter_check', false, $settings, $gallery );
if ( false !== $pre_gallery_html ) {
// If there is HTML, then we stop trying to display the gallery and return THAT HTML.
$pre_output = apply_filters( 'modula_pre_output_filter','', $settings, $gallery );
return $pre_output;
}
/* Get gallery images */
$images = apply_filters( 'modula_gallery_before_shuffle_images', get_post_meta( $atts['id'], 'modula-images', true ), $settings );
$shuffle_permitted = apply_filters('modula_shuffle_grid_types',array('creative-gallery','grid'),$settings);
if ( isset( $settings['shuffle'] ) && '1' == $settings['shuffle'] && in_array($type,$shuffle_permitted) ) {
shuffle( $images );
}
$images = apply_filters( 'modula_gallery_images', $images, $settings );
if ( empty( $settings ) || empty( $images ) ) {
return esc_html__( 'Gallery not found.', 'modula-best-grid-gallery' );
}
do_action('modula_extra_scripts', $settings);
// Main CSS & JS
$necessary_scripts = apply_filters( 'modula_necessary_scripts', array( 'modula' ), $settings );
$necessary_styles = apply_filters( 'modula_necessary_styles', array( 'modula' ), $settings );
if ( ! empty( $necessary_scripts ) ) {
$script_manager->add_scripts( $necessary_scripts );
}
if ( ! empty( $necessary_styles ) ) {
foreach ( $necessary_styles as $style_slug ) {
if ( ! wp_style_is($style_slug, 'enqueued') ) {
wp_enqueue_style($style_slug);
}
}
}
$settings['gallery_id'] = $gallery_id;
$settings['align'] = $atts['align'];
$template_data = array(
'gallery_id' => $gallery_id,
'settings' => $settings,
'images' => $images,
'loader' => $this->loader,
// Gallery container attributes
'gallery_container' => array(
'id' => $gallery_id,
'class' => array( 'modula', 'modula-gallery' ),
),
// Items container attributes
'items_container' => array(
'class' => array( 'modula-items' ),
),
);
ob_start();
$inView = false;
$inview_permitted = apply_filters( 'modula_loading_inview_grids', array( 'custom-grid', 'creative-gallery', 'grid' ), $settings );
if ( isset( $settings['inView'] ) && '1' == $settings['inView'] && in_array($type,$inview_permitted) ) {
$inView = true;
}
/* Config for gallery script */
$js_config = $this::get_jsconfig( $settings, $type, $inView );
$template_data['gallery_container']['data-config'] = json_encode( $js_config );
/**
* Hook: modula_gallery_template_data.
*
* @hooked modula_add_align_classes - 99
*/
$template_data = apply_filters( 'modula_gallery_template_data', $template_data );
echo $this->generate_gallery_css( $gallery_id, $settings );
do_action( 'modula_before_gallery', $settings );
$this->loader->set_template_data( $template_data );
$this->loader->get_template_part( 'modula', 'gallery' );
do_action( 'modula_after_gallery', $settings );
$html = ob_get_clean();
return $html;
}
Code file location:
modula-best-grid-gallery/modula-best-grid-gallery/includes/public/class-modula-shortcode.php
Modula [modula-make-money] Shortcode
The Modula Best Grid Gallery shortcode is a function that was designed to handle affiliate links. However, the functionality has been removed, so it currently returns an empty string.
Shortcode: [modula-make-money]
Examples and Usage
Basic example – The shortcode below is used to call the ‘modula-make-money’ function, which was previously removed. Therefore, it does not return any value or content.
[modula-make-money /]
Advanced examples
While the ‘modula-make-money’ function does not currently have any attributes or parameters, if it were to be reinstated, attributes could be used to customize its functionality. Below are examples of how this might look:
Example 1: Using the shortcode to specify an affiliate ID. This would allow the function to return content related to the specified affiliate.
[modula-make-money affiliate_id="123" /]
Example 2: Using the shortcode to specify both an affiliate ID and a product ID. This would allow the function to return content related to the specified affiliate and product.
[modula-make-money affiliate_id="123" product_id="456" /]
It’s important to note that these examples are hypothetical, as the ‘modula-make-money’ function does not currently accept any parameters or return any content. However, if the function were to be reinstated with added functionality, these examples demonstrate how attributes could be used to customize its output.
PHP Function Code
In case you have difficulties debugging what causing issues with [modula-make-money]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'modula-make-money', array( $this, 'affiliate_shortcode_handler') );
Shortcode PHP function:
function affiliate_shortcode_handler( $atts ) {
// This functionality was removed.
return '';
}
Code file location:
modula-best-grid-gallery/modula-best-grid-gallery/includes/public/class-modula-shortcode.php
Conclusion
Now that you’ve learned how to embed the Modula Best Grid Gallery Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply