You must put your gallery.php
in the same theme folder, where the theme’s functions.php
resides. Then add a single line in functions.php
:
get_template_part('gallery','');
It’ll include the gallery.php
file into functions.php
and gallery.php
will behave like functions.php
.
So, you have to keep in mind that, functions.php
file is a file for WordPress and PHP functions. So anything out-of-format without proper formatting may occur error into the whole site – and functions.php
is a core file of any theme.
I don’t think it’s impossible using WP_Query()
inside a functions.php
– but you have to format and place it properly.
Related Posts:
- Manually set global $post vars with an ID, in order to use template tags
- Is it possible to define a template for a custom post type within a plugin independent of the active theme?
- Ways to have multiple front-page.php templates that can be swapped out?
- Output before and after the loop
- Define Function in functions.php or plugin and call in theme loop
- Trying to avoid including wp-load.php
- How can I let users to access plugin functions based on roles?
- Template for custom post type shows all posts instead of just one
- Fastest way to loop through all posts?
- do_action and hook methods
- How does WordPress ensure plugins run at the same time and how does it solve a plugin’s dependency on another one?
- post expire after x days
- Can’t get custom posts of taxonomy to show
- Display content from custom post type if match to main post category
- how do i remove posts from a WP_Query so the pagination is right?
- Open Post Thumbnail in New Child Theme File in WordPress
- Override global query results without hooks
- Issue using wp-load.php in WordPress Plugin Development
- Fetch Children of Grouped Products Inside WooCommerce Product Loop
- Insert content of a post into another
- Problem with the Loop – want to limit the access to three free articles
- Using wpdb without loading all plug-ins via wp-load.php
- WordPress Plugin manipulate have_posts()
- Get User_id outside wordpress,
- Calling the_excerpt from inside a plugin template file
- Recent posts per category loop?
- Import Instagram post to WordPress blog post
- Bulk update wordpress posts
- How to get a list of bundled products using wp_query in woocommerce
- Where to find the code used to render a page that has a shortcode and a template defined?
- wp-load.php redeclares classes
- Loop in elementor custom widget not working
- get_users(); Is an Undefined Function When Used in Cron Job
- Trying to add_action in a loop
- Loop returns the current page’s permalink and guid instead of the post in the loop
- Get post content from outside the loop with plugin shortcode usability
- Price comparison table based on Custom Post Type?
- Show related posts based of current ACF field name in a single page post (a loop within loop)
- Remember the Meta Value With Radio Buttons
- PHP mobile redirect Endless loop
- Output after specific post in the loop
- Plugin is creating posts twice
- Polldaddy doesn’t show up on own theme
- Add custom PHP and HTML to the_content()
- Multiple images per post – Show random image elsewhere
- How to modify the Loop from a plugin (instead of a theme)
- Hook from plugin doesn’t fire up from external PHP script
- i need to make custom cron_schedule with custom interval time as a parameter into a custom payment gateway plugin wordpress
- I created a plugin with ‘view page’ that uses MYSQL + PHP. When I use wp_insert_post(), it turns everything to HTML
- how to define a html folder to make it work with WordPress commands
- Getting Fatal error: Uncaught Error: Call to undefined function plugin_dir_path() when linking to another file within my wordpress plugin
- Can’t add new plugin or themes on a wordpress multisite network from the primary site as administrator. Error: ERR_TOO_MANY_REDIRECTS
- Create post loop that displays pages by cat ID
- Place content inside the Post Loop
- Retrieve data from multiple WordPress sites using PHP script
- Cannot reset a loop in a plugin template
- Displaying image from a repeatable group
- Multiselect value in wp_query
- Advanced Custom Fields (ACF) Plugin – Random Image in Sidebar
- ‘all’ hook and add_action issue (class based plugin)
- Fake Single WordPress Post (Page) Loop
- Get Core Functionality from Within a (Secondary) Plugin File
- WordPress repository forbids me call wp-load.php in non-WordPress file
- single.php fires more than once after clicking on any post to view with different post id each time
- How do i use postMash to order posts in a custom loop?
- How can I save a setting field with multiple checkbox options generated by a foreach loop on a custom wordpress admin page?
- Getting Post Permalink Outside of Loop Not Working
- Trying to display posts but getting the pages as output
- How to dispaly post informations (such as titles) in an admin plugin menu page?
- Outputting custom field query from a plugin to the website header
- How to display content depending on the Woocommerce Product Category
- Page with redirect
- FacetWP custom display based on post type [closed]
- wordpress on localhost lamp doesn’t let me install plugins
- How do I get Version of all active plugins programmatically?
- How to link to YouTube videos with thumbnails?
- Storing image gallery plugin data
- wordpress custom login successful redirect hook
- Is there any site where i can found good documentation of wp-ecommerce plugin?
- flush_rewrite_rules() not working on plugin activation
- Determine plugin name from within plugin_action_links filter
- prettyPhoto media loading very slowly in Chrome
- Shortcode in widget is printing before the title [duplicate]
- Automatic Updates Individual Plugins Not Working
- Problem with updating a plugin
- Unable to add TAB character to post?
- Restrict content based on buy woocommerce product
- Can I use register_settings and unregister_setting once the settings page has loaded?
- posts from multiple post types in one slider
- How to customize this theme? [closed]
- How Should Custom Functions Be Called For Single Posts?
- Social share buttons text shows up on post excerpts
- Importing csv file
- How to display the category name in the tab and post inside the tab in WordPress?
- Want to build parent-child relationships between custom post types created with CPT UI
- best way to upload a large file to wordpress using wp all import
- Payment failed but order is placed on wp site
- Code fails in plugin file but works in functions.php
- Display_rows() and column_cb() strange behaviour
- I need to insert a captcha for all comments in word press