---
title: "Display a Gallery in PHP code"
id: "177277"
type: "knowledgebase"
slug: "display-a-gallery-in-php-code"
published_at: "2019-09-28T04:51:51+00:00"
modified_at: "2020-12-08T18:19:52+00:00"
url: "https://fooplugins.com/documentation/foogallery/developers/display-a-gallery-in-php-code/"
markdown_url: "https://fooplugins.com/documentation/foogallery/developers/display-a-gallery-in-php-code.md"
excerpt: "Sometimes you want to render a FooGallery from your PHP code. It is usually because you want to create a custom theme template to display a specific gallery. The foogallery_render_gallery function Rendering a gallery in PHP code is done using..."
taxonomy_knowledgebase_cat:
  - "FooGallery - Developers"
---

[FooGallery – Developers](https://fooplugins.com/documentation/foogallery/developers/)

# Display a Gallery in PHP code

## Related Articles

- [Change Gallery Output HTML](https://fooplugins.com/documentation/foogallery/developers/change-gallery-output-html/)
- [Override Image Captions](https://fooplugins.com/documentation/foogallery/developers/override-image-captions/)
- [Add NoFollow to Custom Links](https://fooplugins.com/documentation/foogallery/developers/add-nofollow-custom-links/)
- [Custom Hover Icons](https://fooplugins.com/documentation/foogallery/developers/custom-hover-icons/)
- [Force Thumbnail Links To Load In New Tab](https://fooplugins.com/documentation/foogallery/developers/force-thumbnail-links-load-new-tab/)
- [Add Class To All Gallery Thumbnail Links](https://fooplugins.com/documentation/foogallery/developers/add-class-gallery-thumbnail-links/)
- [Override Create Gallery Page Content](https://fooplugins.com/documentation/foogallery/developers/override-create-gallery-page-content/)
- [FooGallery Developer 101](https://fooplugins.com/documentation/foogallery/developers/foogallery-developer-101/)
- [Developers](https://fooplugins.com/documentation/foogallery/developers/developers/)
- [Customize Your Gallery Using Custom CSS](https://fooplugins.com/documentation/foogallery/developers/customize-gallery-custom-css/)
- [Common FooGallery Custom CSS Customisation Tweaks](https://fooplugins.com/documentation/foogallery/developers/common-foogallery-custom-css/)
- [FooGallery Hooks](https://fooplugins.com/documentation/foogallery/developers/foogallery-hooks/)
- [Auto License Activations using wp-config.php](https://fooplugins.com/documentation/foogallery/developers/auto-license-activations-using-wp-config-php/)

**Need more help?** Browse all documentation or open a support ticket.

[All docs](/documentation/)

[Support](/support/)

Sometimes you want to render a FooGallery from your PHP code. It is usually because you want to create a custom theme template to display a specific gallery.

## The foogallery_render_gallery function

Rendering a gallery in PHP code is done using the **foogallery_render_gallery** function. It takes 2 parameters:

- $gallery_id (required) – the id of the gallery you want to show
- $args (optional) – arguments to override any setting for the gallery

Here is some code you can use to safely display/render a gallery in PHP:

```
// you first need to know which gallery you want to render.
// you can hard-code this value or get it from somewhere else
$gallery_id = 123;

// next, do a check to make sure FooGallery is loaded
if ( function_exists( 'foogallery_render_gallery' ) ) {
    
    //render the gallery!
    foogallery_render_gallery( $gallery_id );

}Code language: PHP (php)
```

You can also get more advanced, and pass arguments to the the function. These arguments will override any setting that you have saved for your gallery. An example is changing the sort order, or limit the number of images to show in the gallery. Here is an example:

```
$gallery_id = 123;
$args = array(
    'limit' => 5, // only show 5 thumbs in the gallery
    'caption_title_source' => 'alt' // change the captions titles to use ALT text rather
);

// next, do a check to make sure FooGallery is loaded
if ( function_exists( 'foogallery_render_gallery' ) ) {
    
    //render the gallery with arguments!
    foogallery_render_gallery( $gallery_id, $args );

}Code language: PHP (php)
```

Resources

## Find the right next step

Use this grid for documentation indexes, support routes, account links, affiliate resources, and download pages.

![Image](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)

### Documentation

Search setup guides, product docs, and troubleshooting articles.

[Browse docs](/documentation/)

![Image](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)

### Support

Open a ticket with product details so we can help quickly.

[Get support](/support/)

![Image](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)

### Licensing

Review account, renewal, refund, and license information.

[View details](/licensing/)
