Skip to main content
16 votes
Accepted

How to move page template files like page-{slug}.php to a sub-directory?

How Page Templates are loaded: According to the default WordPress Template Hierarchy, a page request loads a template based on the priority and naming as stated below: Custom Page Template: if ...
Fayaz's user avatar
  • 8,937
12 votes

How to get the current plugin name?

Within the plugin's main PHP file: $plugin_data = get_plugin_data( __FILE__ ); $plugin_name = $plugin_data['Name'];
Mark Howells-Mead's user avatar
10 votes
Accepted

What WP folder can I use to write files to?

Best place is the uploads directory - it'll be writable by the server, and it's the defacto directory for storing any user-generated/uploaded files: $dirs = wp_upload_dir(); $path = $dirs['basedir']; ...
TheDeadMedic's user avatar
  • 36.5k
9 votes

Getting Images from theme's directory in pages

<img src="<?php echo esc_url( get_template_directory_uri() . '/images/logo.jpg' ); ?>" alt="" > Try this. It should work. You have to concatenate the results from ...
Kaif Ahmad's user avatar
8 votes
Accepted

Non-WordPress page in subdirectory under WordPress page

As @MarkKaplun suggests, it would be preferable to store this non-WordPress file in a different area of the filesystem altogether and rewrite the URL in .htaccess. Instead of mimicking the WordPress ...
MrWhite's user avatar
  • 3,881
7 votes

Multisite in subfolder - How to make new sites to be in same level subfolders as the main site

After these years I hope this will still answer your question... I think I've got the situation working you want. Allthough I don't have the Wordpress installation in '/subfolder/', but I've a ...
Piemol's user avatar
  • 171
6 votes

Custom Post Type Templates from Plugin Folder?

I would like to point out that when you are using the filter method for this, it is extremely important to prioritize the filter like so: add_filter('single_template', 'my_custom_template', 99); If ...
RBizzle's user avatar
  • 61
5 votes
Accepted

Rename UPLOADS folder with custom WP_CONTENT_DIR

After digging around, I ended up with using upload_dir filter. Here is what I tried in functions.php to change uploads to media. Hope it can help someone too :) add_filter('upload_dir', function($...
Minh Tri's user avatar
  • 3,419
5 votes

Getting Images from theme's directory in pages

Shortcode is the way to go, something like this (in functions.php or as plugin) would work: // [template_dir image="something.jpg"] add_shortcode( 'template_dir', function( $atts ){ return ...
sandrodz's user avatar
  • 614
5 votes

Multisite: differences between subdomain and subdirectory mode? Can it be switch after installation?

From a user perspective there are two noticeable differences. First of all the GUI for creating new sites. Either it shows an input field for the first segment of the URL path (subdirectory) or an ...
David's user avatar
  • 3,285
5 votes
Accepted

Images loaded as background-image are shown but <img>s aren't

Relative paths in css files are relative to the css file location, but in PHP they are relative to the website URL not to the php file location in the server. So to make sure you get the right URL ...
Ibrahim Mohamed's user avatar
4 votes

Add multiple plugin directories

I don't personally have any interest in modifying the UI, but I'd love a more organized file system layout, for several reasons. To that end, another approach would be to use symlinks. wp-content ...
Ian Dunn's user avatar
  • 4,837
4 votes

Multisite in subfolder - How to make new sites to be in same level subfolders as the main site

Piemol's answer is great and worked for me. However, I was unable to log into any of my sites except the main site. Upon inspecting my cookies, I discovered WordPress was making a cookie for only my ...
kittee's user avatar
  • 41
4 votes

Getting Images from theme's directory in pages

It's not possible to use PHP code in editor. You can use an image with full path. <img src="/wp-content/themes/your-theme/assets/images/1.jpg" /> In general I would avoid using theme specific ...
Ajay Tank's user avatar
4 votes

Rename UPLOADS folder with custom WP_CONTENT_DIR

If you look at the source of _wp_upload_dir, you'll see: if (defined('UPLOADS') && ! (is_multisite() && get_site_option('ms_files_rewriting'))) { $dir = ABSPATH.UPLOADS; $url =...
gmazzap's user avatar
  • 46.2k
4 votes

What WP folder can I use to write files to?

The only directory with guaranteed write access is the upload directory. Everything else might be protected. Nowadays, we deploy sites with Composer, keep everything under version control and create ...
fuxia's user avatar
  • 107k
4 votes

Creating directory in uploads: mkdir vs wp_mkdir_p

There is not much a difference but, for wp_mkdir_p() we can only pass the full path to attempt to create a folder. It is recursive directory creation function which check for the file_exists() or not. ...
Alok Shrestha's user avatar
4 votes

How to fix: "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."

Caveat I know this question is a little out of date and our question/issue is technically regarding an Azure Wordpress Resource not a hosted environment... but I thought it might be helpful to answer ...
Ryan's user avatar
  • 221
4 votes

Non-WordPress page in subdirectory under WordPress page

You can do it by adding a rule to htaccess that will load that page for that specific URL, and add the rule before the wordpress rules. For that it do not make a difference where exactly the page is ...
Mark Kaplun's user avatar
  • 23.4k
4 votes
Accepted

How to install WordPress Multisite with different domains under the same subdirectory?

You don't need domain mapping in current versions of WP, it's built in. You just need to edit the site Settings (under Network Admin, Sites, click on site then Edit). Enter the URL for the site (...
Rick Hellewell's user avatar
4 votes
Accepted

How to get path or root of plugin folder, not file or dir?

How about just define a constant that stores the plugin's root path? Define path constant For calling numerous files, it is sometimes convenient to define a constant: define( 'MY_PLUGIN_PATH', ...
Sally CJ's user avatar
  • 39.4k
3 votes
Accepted

.htaccess for wordpress inside another wordpress install

It was a server missconfiguration in httpd.conf: <Directory /> AllowOverride None </Directory> had to be changed in AllowOverride All. I should have realized this sooner, but it ...
tao's user avatar
  • 985
3 votes

Can I change get_template_directory_uri()?

I'd like to contribute a more detailed answer as I found figuring out 'add_filter()' was quite frustrating. In order to edit the hook for get_template_directory_uri(), you need to add filter as ...
Bradan's user avatar
  • 31
3 votes
Accepted

Why should I use "Organize my uploads into month- and year-based folders" option? (Cons/Pros)

This is one of the many optional features in WordPress.There is no real benefit in using any of these 2 structures, but here is some details for you: Organization: When you are building a website ...
Johansson's user avatar
  • 15.3k
3 votes
Accepted

Wordpress page templates in a directory

The file needs a template header and will only behave as a user-selectable custom page template. True special templates like page-$slug.php that match the post's slug will only work when they live in ...
TheDeadMedic's user avatar
  • 36.5k
3 votes
Accepted

Should custom directories be created under the wp-content directory?

If there is a need for custom files e.g. CSS that need to be called, should a custom directory e.g. css be created under wp-content e.g. wp-content/css? No, never. You should not do this under any ...
Tom J Nowell's user avatar
  • 59.9k
3 votes
Accepted

What are the implications of having main plugin file name different to plugin slug?

It's only a good pratice to adopt this naming convention. As long as you have in the header of your main file the meta (at last Plugin name: Name of Your Plugin, WordPress will automatically recognize ...
PhpDoe's user avatar
  • 199
2 votes

What WP folder can I use to write files to?

One alternative approach us to have a PHP file that gets the theme options and outputs the CSS and enqueue that directly instead. eg. wp_enqueue_style('custom-css',trailingslashit(...
majick's user avatar
  • 5,091
2 votes
Accepted

Is it possible to place custom post type files inside a folder in theme directory?

You may want to look at the TwentySixteen theme, which does it this way: In single.php: get_template_part( 'template-parts/content', 'single' ); Several templates are grouped in the 'template-parts'...
Manu's user avatar
  • 817
2 votes

How to get the current plugin name?

This will give you the plugin folder name regardless of where the file is located and not having to know anything about the directory structure of the plugin. $plugin_folder_name = reset(explode('/', ...
Kerkness's user avatar
  • 141

Only top scored, non community-wiki answers of a minimum length are eligible