Skip to main content
12 votes

How to convert the file path to a URL of the same file?

Or global function abs_path_to_url( $path = '' ) { $url = str_replace( wp_normalize_path( untrailingslashit( ABSPATH ) ), site_url(), wp_normalize_path( $path ) ); ...
Serge Liatko's user avatar
6 votes
Accepted

Installation failed: Could not create directory - CentOS 7

SELinux was the problem. Its enforcement was, for lack of a better term, overriding the file permissions and keeping Wordpress from writing to any of the files. To solve the issue, I did the ...
Kyle Martin's user avatar
6 votes
Accepted

What dependencies should I load and to use the WP_Filesystem?

What is the best way to load the dependencies for the WP_Filesystem? The first or the second code part? WP_Filesystem() is used in conjunction with the global $wp_filesystem variable, so if you use ...
Sally CJ's user avatar
  • 39.9k
5 votes

How to convert the file path to a URL of the same file?

Here is my solution for this: function convert_url_to_path( $url ) { return str_replace( wp_get_upload_dir()['baseurl'], wp_get_upload_dir()['basedir'], $url ); }
Serhiy Zaharchenko's user avatar
4 votes
Accepted

How to replace file_get_contents() with a Wordpress Filesystem call

Firstly add this two line to your functions.php file. Sorry I forgot to mention about this earlier. require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'; require_once ABSPATH . 'wp-...
Sabbir Hasan's user avatar
  • 1,389
4 votes

How to replace file_get_contents() with a Wordpress Filesystem call

Solution 01 $wp_filesystem = new \WP_Filesystem_Direct(null); $svg= $wp_filesystem->get_contents(get_stylesheet_directory_uri() . '/assets/images/Search_Glyph.svg'); Solution 02 $remote_svg_file = ...
Ejaz UL Haq's user avatar
3 votes

What files are safe to delete after a security breach in WP content folder?

The only safe thing to do is to restore the site from a known clean backup. Hacker could have inserted backdoor users or other vulnerabilities in your DB, something you are not going to be able to ...
Mark Kaplun's user avatar
  • 23.7k
3 votes
Accepted

How do I edit the php/html for a particular post?

It's useful to understand how things work in WP. Content (pages, posts) are stored in the WP database. The 'style' of the site - how it works, how pages are built, how it looks - are in the theme of ...
Rick Hellewell's user avatar
3 votes

Relative file paths in CSS when linking directly (not enqueuing)

Relative paths in CSS are relative to the stylesheet file. So if you have this structure: - style.css - images/ -- logo.png -- background.jpg Then the paths in CSS for the images would be url(images/...
Jacob Peattie's user avatar
3 votes
Accepted

Can't write pdf file to upload directory using FPDF

$name apparently contains a URL. That won't work. Set it to a local path, as you did with $filename: $upload_dir = wp_upload_dir(); $filename = $upload_dir["basedir"] . '/deals/deal' . $page-&...
janh's user avatar
  • 2,748
3 votes

Adding Adobe files to a wordpress site

Allowing file types outside of WP's defaults exposes your site to some security risks, and some hosts don't allow certain filetypes. If your host allows these filetypes, you can use the following ...
WebElaine's user avatar
  • 9,664
3 votes
Accepted

Can I delete `wp-config-sample.php` after installing and configuring Wordpress?

Yes, you can safely delete that file. It's a template of what a minimal wp-config.php looks like, so as soon as you have a working wp-config, you don't need it. It will never be restored unless you ...
mozboz's user avatar
  • 2,608
3 votes
Accepted

Can WP plugins access files outside the installation folder?

Can they theoretically develop a WP plugin to access the files (or even WP config, including DB credentials) of another WP installation? Yes. If your folders are owned by the same user, run as the ...
Tom J Nowell's user avatar
  • 60.6k
2 votes

How to give image source in wordpress page editor?

You cannot use PHP in the content editor, just write the full path to your image. <img src="/css/_include/img/slider-images/1.jpg" alt="Image" data-fullwidthcentering="on">
Savan Dholu's user avatar
2 votes

How to give image source in wordpress page editor?

Absolute URLs As other have said, you need to use the full URL for your image src attribute, or the browser will not be able to find it. WordPress provides the function get_template_directory_uri() ...
gmazzap's user avatar
  • 46.3k
2 votes
Accepted

How to move Wordpress theme files into a subfolder without breaking the theme?

Out of the box WP relies on Template Hierarchy to resolve and load template. The default assumption is that (most) template are in the root of the theme and follow the naming conventions. Placing ...
Rarst's user avatar
  • 100k
2 votes

How to convert the file path to a URL of the same file?

In a theme, if you want to literally convert a file system path to a URL for a given file, you would do this: $url = str_replace( get_stylesheet_directory(), get_stylesheet_directory_uri(), $...
Corey C.'s user avatar
2 votes
Accepted

Theme, Wordpress Version, MySQL Version, PHP Version Update affected files and folders

How do I keep my Files during Wordpress and Theme Updates? Don’t edit core WordPress files or the files of themes or plugins you didn’t develop yourself. If those are updated they are replaced ...
Jacob Peattie's user avatar
2 votes

Is there a way to get a path to the theme directory without the server name?

Yes get_template_directory: get_template_directory(): string Retrieves template directory path for the active theme. Returns an absolute server path (eg: /home/user/public_html/wp-content/themes/...
Tom J Nowell's user avatar
  • 60.6k
1 vote

Wordpress Login doesnt respond after using Filezilla to upload my files on the server

Check the wp-config.php file on your site. It should contain the database credentials (db name, user, password) for your site. Verify those values. Maybe even change the password via your hosting ...
Rick Hellewell's user avatar
1 vote
Accepted

Adding regular php file to site

You could accomplish this by setting up a redirect. If you're using an Apache server, for your example, you would add this to .htaccess above the WordPress block: RewriteEngine On RewriteRule ...
WebElaine's user avatar
  • 9,664
1 vote
Accepted

Plugin writing: access file that was just uploaded

When you use media_handle_upload() to upload a file, it creates the attachment post in the database and return the ID of the attachment, or a WP_Error if the upload failed. This ID of the attachment ...
Qaisar Feroz's user avatar
  • 2,147
1 vote
Accepted

Failed opening required

WordPress includes many functions for determining paths and URLs to files or directories within plugins, themes, and WordPress itself. $plugin_dir = plugin_dir_path( __DIR__ ); // wp-content/...
Qaisar Feroz's user avatar
  • 2,147
1 vote

WordPress and plugins can't update ("inconsistent file permissions" error)?

Try to run these commands (Commands are for both Dashboard and ftp) sudo usermod -aG www-data $USER sudo chown -R www-data:www-data /var/www sudo chmod -R 774 /var/www
SHEESHRAM's user avatar
1 vote
Accepted

Should I store critical css in the database or in my theme's filesystem?

Preface It would be best to see what kind of caching options are available through your host. If you can use an object cache, CDN, or anything like that, you could decrease the load on your server. If ...
phatskat's user avatar
  • 3,174
1 vote

Relative file paths in CSS when linking directly (not enqueuing)

You should be using get_stylesheet_directory_uri(). This is the same function as get_template_directory_uri() but it uses the directory of the child theme. as an example: get_template_directory_uri(...
rudtek's user avatar
  • 6,333
1 vote
Accepted

Look for a file in a theme before loading from plugin

Woocommerce use locate_template for checking if file exists in theme or not
Malay Solanki's user avatar
1 vote

wp-config.php file permissions

On a VPS with Ubuntu run the following commands from within /var/www/mysite.com/public_html: sudo chown -R myname:www-data /var/www/mysite.com/ Then run: sudo find /var/www/mysite.com/ -type d -...
Daniel's user avatar
  • 351
1 vote

Is it better to store images and other files in the root directory or the theme directory

It depends on what you like to do really. I am saying that because the question is not very clear. If you are talking about images you upload as part of your content (for example, a feature image of ...
Greeso's user avatar
  • 2,204
1 vote

Is it better to store images and other files in the root directory or the theme directory

In general any customization you have to wordpress core (themes, plugins, uploaded files, etc) should live under the wp-content directory. On the practical side, you should never use relative urls ...
Mark Kaplun's user avatar
  • 23.7k

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