Questions tagged [include]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
74 votes
3 answers
123k views

get_template_directory_uri pointing to parent theme not child theme

The problem I am having is that the get_template_directory_uri is pointing to the parent theme like site/wp-content/themes/twentythirteen/myGallery/gallery_functions_include.php but I want it to ...
Elroy Fernandes's user avatar
56 votes
7 answers
52k views

Passing variables through locate_template

While I've typically used include or require on their own to save long term code maintenance I've started to use get_template_part and locate_template as using built in WordPress stuff is always best. ...
curtismchale's user avatar
  • 2,599
32 votes
3 answers
33k views

Is there any way to use get_template_part() with folders?

I'm wondering if there is any way to use get_template_part() with folders? My main folder has a lot of files now because I put every re-usable element in a separate file. I'd like to put them in ...
Paul's user avatar
  • 2,150
14 votes
3 answers
88k views

The proper way to include/require PHP files in WordPress

I'm a new WordPress developer and recently I've been having problems (on multiple sites) with include_once and require_once for PHP files. If I include (get_theme_directory_uri() . 'subdir/file') the ...
caffeine's user avatar
  • 141
11 votes
3 answers
33k views

How do I replace a function, declared inside a plugin's class, in functions.php?

I want to modify a function in a plugin. It is declared in the plugin's main file like this: class WCPGSK_Main { ... public function wcpgsk_email_after_order_table($order) { ... } } Add ...
Igor Skoldin's user avatar
11 votes
2 answers
9k views

Include WP_Query in my own PHP file?

I want to write a cronjob for myself. But I need to get access to WP_Query and the permissions to delete posts etc. My question now is, how can I include the WP_Query function to my own PHP file and ...
Jan's user avatar
  • 307
10 votes
1 answer
4k views

Should we use get_template_part() in functions files instead of include_once?

I'm using the theme-check plugin to check my theme for errors and recommendations, I'm using get_template_part() in theme files like header.php and index.php but in functions.php I'm using ...
Pierre's user avatar
  • 1,014
9 votes
4 answers
42k views

Order by & include array by specific post ids

I have the following: <?php $num_cols = 2; // set the number of columns here $args = array( 'post_type' => 'testimonials', 'posts_per_page' ...
Nina's user avatar
  • 193
9 votes
2 answers
12k views

is_plugin_active() returning false on active plugin

So I have the following in an include in my theme file: include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); if ( is_plugin_active( WP_PLUGIN_DIR . '/woocommerce/woocommerce.php' ) ) { $...
Brian's user avatar
  • 814
9 votes
2 answers
12k views

Unable to check if plugin is active

I am working on a custom theme using ACF. I would like to check if the plugin is active or not. I am using this code: <?php include_once( ABSPATH . 'wp-content/plugins/advanced-custom-fields-pro/...
Johann's user avatar
  • 867
9 votes
3 answers
22k views

How to include a plugin's php file to another plugin functions file [duplicate]

I need to customize the output of the shortcode of plugin A by using a function of plugin B. So I alter the shortcode function of plugin A by inserting a condition to check the value of the function ...
vadims's user avatar
  • 353
7 votes
6 answers
87k views

Include a external PHP file into a Wordpress Custom Template

Is it possible to include a external PHP file into a custom template? I'm trying to add a blog into my site. I already have the header, footer, and sidebar layout in my site. Can I use those in my ...
Jeremi Liwanag's user avatar
6 votes
5 answers
51k views

Include PHP file in Content using [shortcode]

Here is what I have I am not having any lucking finding how to simply include a file in the content editor using a shortcode. For Example if I wanted to include form.php inside my Contact Page how ...
Eric Downs's user avatar
5 votes
1 answer
40k views

Include files in functions.php

This is a rewritten post since the way I worded my old post totally confused everyone. MikeSchinkel shows how he uses Include files in his theme's functions.php file In this Stackexchange post: ...
user3438958's user avatar
5 votes
1 answer
4k views

What is the right way to include a wp-admin file in your theme?

I'm trying to use wp_delete_user() in my theme, to allow a user to delete their account from the front-end. Turns out that the wp_delete_user() is not defined unless /wp-admin/includes/user.php has ...
kdev's user avatar
  • 843
5 votes
2 answers
16k views

How to prevent wordpress from loading old versions of jquery in wp_head();?

I noticed my twenty twelve theme is including outdated versions of jquery and js so I want to replace the scripts with the newer versions, however the scripts are in the file included by wp_head() (...
Lisandro Vaccaro's user avatar
4 votes
2 answers
8k views

Why does including a file in theme's functions.php not work?

For example, if I write some code (e.d. add a custom post type or something) in my theme's functions.php, it works fine. If I move it to a new file, then include() the file in my theme's functions.php ...
trusktr's user avatar
  • 781
4 votes
1 answer
6k views

Problem requiring/including plugin files with plugin_dir_path( __FILE__ )

I am trying to write a WordPress plug-in. In my project I have three PHP files. My plug-in file Widget for the plug-in Data installation I need to install data table on plug-in activation. For that ...
Bushra Shahid's user avatar
4 votes
2 answers
636 views

load/require specific php files for specific pages/templates/post types

I have a plugin with multiple php files. I want to load some of them only when specific template files are loaded. I don't want to load everything. Currently, I'm doing it with add_action( 'wp', '...
eddr's user avatar
  • 41
3 votes
4 answers
1k views

Include Javascript as Plain (No file inclusion)

Is there a way to append Javascript to the body in the script tag without using a file? Normally you would do it with wp_enqueue_script('name', 'path/to/js/file'); Is there a way to include js ...
Ronon's user avatar
  • 219
3 votes
2 answers
17k views

How can I include JavaScript that use jQuery on admin side

I try this: add_action('admin_print_scripts', 'custom_admin_scripts' ); function custom_admin_scripts() { echo '<script type="text/javascript" src="' . get_bloginfo('stylesheet_directory') ...
Shimon S's user avatar
  • 887
3 votes
1 answer
4k views

bloginfo('stylesheet_directory') vs. get_stylesheet_directory_uri() and include('file.php') vs. get_template_part()

In my custom theme I'm using <img src="<?php bloginfo('stylesheet_directory'); ?>/images/logo.jpg"/> to load my custom logo. I'm using a custom sidebar for front-page.php and that's why I ...
Mayeenul Islam's user avatar
3 votes
3 answers
2k views

Sort users in get_users() in custom order

<?php $blogusers = get_users('include=5,6,2,7,12,8'); foreach ($blogusers as $user) { ... } ?> Right now, these users will sorted by first name. How do I sort this in the order the ...
nicolas's user avatar
  • 265
3 votes
1 answer
9k views

ob_get_clean returns empty string, ob_get_flush outputs string

I am utilizing a template-type system, to filter the_content. My filter contains this partial code: ob_start(); include_once ( self::$dir . 'views/templates/' . $post_type . '/' . $display . '.php' );...
Josh Levinson's user avatar
3 votes
2 answers
235 views

How can I avoid code duplication for a blog with lots of source code?

I'm writing a tutorial on using the R language to do some applied statistics. An example post is: http://mcmcinirt.stat.cmu.edu/archives/223 I would like to have all of the blocks of source code be ...
Nathan VanHoudnos's user avatar
3 votes
1 answer
4k views

passing argument to get_template_part() or a better way to code

I have this include … event-list.php <?php /** * The loop that displays upcoming events */ ?> <ul class="event-items"> <?php $yesterday = time() - 24*60*60; $args = array( ...
mathiregister's user avatar
2 votes
3 answers
870 views

where to include a php file

I have a php file with some variables which I would like to use. When I include it in the header.php the variables in that file are not recognized at footer.php and some other places. Where is the ...
Ofer's user avatar
  • 23
2 votes
3 answers
10k views

the_author() not working outside the loop

I have the following code on index.php and I want to include this line of code (bellow) to display author info on top of the loop. <?php include 'author-top.php'; ?><!--author--> I want ...
Raul's user avatar
  • 111
2 votes
2 answers
7k views

Passing variables to template parts

I have one template file videos.php which has the following line of code in it (aswell as a load of HTML): <?php get_template_part('loop', 'feed-videos' ); ?> inside that template part, I have ...
user avatar
2 votes
3 answers
7k views

Add few specific post ids to wp_query

I have following args to get recent posts, $args = array( 'date_query' => array( array( 'after' => '1 week ago' ) ), 'posts_per_page' => 15, 'ignore_sticky_posts' => 1, '...
Janith Chinthana's user avatar
2 votes
2 answers
2k views

What is the most efficient method for loading widgets in functions.php

I have seen WordPress developers use two different methods for loading custom widgets from the functions.php file. The first: include("functions/my-custom-widget.php"); The second: require_once(...
derekshirk's user avatar
2 votes
2 answers
3k views

Show certain terms from custom taxonomy but exclude 'parent' terms?

I have a custom post type "mycustom_products" (hierarchical) that has custom taxonomies called 'categories' and 'tags' (as many other custom post types do). My custom category is called "...
RodeoRamsey's user avatar
  • 1,707
2 votes
3 answers
846 views

PHP files included in functions.php don't seem to work

This is my first post on WordPress StackExchange, I'll try to be precise. My question is: Is there anything in particular I should do to the files I'm including in my theme's functions.php file? I'...
donnie_g's user avatar
2 votes
1 answer
10k views

ABSPATH not working! Any idea why?

This is what in my wp-config.php : if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/'); I am calling from plugin/pluginName directory to : require_once( ABSPATH . 'wp-includes/...
тнє Sufi's user avatar
  • 1,710
2 votes
3 answers
17k views

Get current user data from external PHP page

I have a PHP page at the same level as the template/theme on WordPress. I need to be able to get the current logged in user details from this page. I have tried this: require_once( $_SERVER['...
user159500's user avatar
2 votes
2 answers
176 views

I need to add a custom "cover" to every new post — plugin or custom setup?

I'm creating a site that's basically like an online book, and every post is a chapter. Each chapter gets a customized, specially designed "cover" page that can't really be designed in the Wordpress ...
Brandon Durham's user avatar
2 votes
3 answers
893 views

How do I use the Simple HTML DOM Parser in plugin when other plugin already uses it?

In a plugin I am currently coding, I want to use the Simple HTML DOM Parser library. However, when I include it require(CPS_PLUGIN_PATH . '/vendor/simple_html_dom.php'); I get this error: Fatal error:...
TheKidsWantDjent's user avatar
2 votes
2 answers
841 views

External system integration with wordpress

I'm writing a web/db application. My clients would like authentication based on whether the user is logged into WordPress. Assuming this application is hosted from within /wordpress I would like to ...
Gareth's user avatar
  • 31
2 votes
1 answer
248 views

Why does get_template_part() break variables?

In PHP, when you include a file, the variables you're using in your current scope are available for use in the included file. When using WordPress's get_template_part(), variables are no longer ...
somebodysomewhere's user avatar
2 votes
3 answers
4k views

How to pass variables with get_template_part?

I am developing a custom theme and i like to pass some variables to selected files. I am calling the view files from functions.php. $var1 = ; $var2 = ; etc include_once('form-views/view-profile.php')...
alex's user avatar
  • 1,122
2 votes
1 answer
797 views

Conditional Ajax inclusion

I have a custom interface that uses 30+ ajax files while running... some files are only used in category.php while othere's are only used in page.php... i include the ajax loader php files in my ...
Sagive's user avatar
  • 2,772
2 votes
1 answer
227 views

Include files for a plugin not including

I have a plugin which I need to include a file in but it doesn't include. Here's the example of the tree: plugin folder /themes /folder2 /somefiles /includeme.php Within themes is /...
equilibrium3's user avatar
2 votes
2 answers
1k views

Including an External File in a Post (and Using Processed Paths)

I have a post that includes a relatively large table that gets updated frequently. Instead of using the (slower) web interface to update the post each time, I installed one of the “run PHP” plugins ...
Synetech's user avatar
  • 311
2 votes
1 answer
17k views

Include Class File in Wordpress

I'm including a Class file in functions.php file require_once get_template_directory() . "/core/classes/General.php"; require_once get_template_directory() . "/core/classes/User.php"; When I do $...
Brian Coolidge's user avatar
2 votes
1 answer
127 views

nowplaying.include.php Will Not Display Results

Cyberchimps.com recommended I post here as they believed there may be a global issue with my request. I thought what I was missing was obvious and simple, but two months into this and being referred ...
SBLee's user avatar
  • 21
2 votes
1 answer
3k views

integrating external php library into wordpress- the right way

If I were to load a custom library into wordpress, what would be the best place to add it? Since there are a bunch of global vars defined at the top of the library, I would not want that to be done ...
Average Joe's user avatar
  • 1,879
2 votes
0 answers
176 views

Change title and meta description in included page (not template)

I'm trying to change title and meta description for pages used for products. The goal is to have the same effect as here: <script>document.title = "<?php echo $new_title; ?>";<...
jackaaxc's user avatar
2 votes
1 answer
184 views

Can I change a variable in a content part while calling it?

I am using a content part for title sections on various sites. I would still like to be able to change the title manually on each page. For this particular case I can‘t use dynamic functions like ...
Jeffrey's user avatar
  • 23
2 votes
1 answer
1k views

Include file from higher level

I created a custom page template where I want to present some data specific for that page. The file is placed in wp-content/themes/themename/page-templates In that file I want to include another ...
gerre's user avatar
  • 23
1 vote
4 answers
12k views

Adding rich text editor to my plugin

I'm trying to add a rich text editor to my own plugin. So I googled it first of course and I found several answers on dev4press and Stack Overflow. This code displays nothing so I tried another ...
Ronny Rook's user avatar

1
2 3 4 5