admin管理员组文章数量:1277896
When we customize a theme in WordPress in custom CSS, so it creates backend custom CSS file and I have to do these tasks which I cant understand openly:
- To save this CSS in a file in the upload folder dynamically.
- And render the custom CSS from the file. (that was just generated dynamically in 1st step above.)
- Remove it from the HTML head section. Otherwise, the custom CSS will be rendered twice. Can anybody help?
When we customize a theme in WordPress in custom CSS, so it creates backend custom CSS file and I have to do these tasks which I cant understand openly:
- To save this CSS in a file in the upload folder dynamically.
- And render the custom CSS from the file. (that was just generated dynamically in 1st step above.)
- Remove it from the HTML head section. Otherwise, the custom CSS will be rendered twice. Can anybody help?
1 Answer
Reset to default 1Please use this method:
// Lets create some test CSS code
$css = '/* Some test CSS */ body {background:red;}';
// Stash CSS in uploads directory
require_once( ABSPATH . 'wp-admin/includes/file.php' ); // We will probably need to load this file
global $wp_filesystem;
$upload_dir = wp_upload_dir(); // Grab uploads folder array
$dir = trailingslashit( $upload_dir['basedir'] ) . 'some-folder/'; // Set storage directory path
WP_Filesystem(); // Initial WP file system
$wp_filesystem->mkdir( $dir ); // Make a new folder for storing our file
$wp_filesystem->put_contents( $dir . 'style.css', $css, 0644 ); // Finally, store the file :D
本文标签: phpSave Custom CSS file in the upload folder dynamically
版权声明:本文标题:php - Save Custom CSS file in the upload folder dynamically? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741259386a2367314.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论