file_exists()
lets you check if a file exists on the local server, by passing it a file path. It cannot be used to check for the existence of files via URL, and you’re passing it the result of get_stylesheet_directory_uri()
, which returns the URL (http:// etc.) to the file, not the path.
The proper way, these days, to get the path to a theme file is to use get_theme_file_path()
, like so:
$filecs = get_theme_file_path( 'css/lucilevi.css' );
$filejs = get_theme_file_path( 'js/lucilevi.js' );
if ( file_exists( $filecs ) ) {
// etc.
}
if ( file_exists( $filejs ) ) {
// etc.
}
Just be aware that because $filecs
and $filejs
are file paths, you cannot pass them to wp_enqueue_style()
, wp_enqueue_script()
, you still need to pass URLs to those.
Related Posts:
- Sending the reset password link programatically
- How to change upload directory in wp_handle_upload
- How do I directly access a PHP file located in my themes folder?
- Only show div on homepage/blog index in wordpress/php
- Calculate percentage of post by category
- file_exists() acting weird
- the_title() & the_content() are retrieving Post details inside a Page, after calling a shortcode
- register_rest_route regex option for base64 or alternate
- Is it possible to use the featured image of a page as a css background without inlining?
- PHP syntax error when using wpdb update?
- Select dropdown not showing selected value php
- Woocommerce – How to get products which have a sale between 20% to 40%? [closed]
- items_wrap not working
- Can is_page() be combined with a switch control structure?
- is it possible to force wordpress to always save thumbnails as ‘jpg’ not ‘png’
- Using shipped version of jquery
- Run a filter when a walker runs
- WordPress (3.9.1) MultiSite Permissions. Is chown the answer?
- have_posts() execution failure
- WordPress with php 5.5 and zend opcache
- Can’t search posts using WP_QUERY inside AJAX Function
- How do I Add HTML to the_excerpt() & the_content() Output?
- Display fields as values in array from external SQL DB
- my posts are saved as drafts
- User’s total comment count excluding comments on their own posts
- Populate dropdown with Child Pages based on Parent Page chosen
- How can I remove a function that has been added to wordpress with add_filter?
- Create a range slider to change font-size with different screens sizes in wordpress customizer api
- do search in two site and show the result in first site
- Are there security or other issues with changing PHP time limit and max input vars?
- What’s the uses of wp_cache_set() or wp_cache_add()?
- How can I pass a custom/dynamic product to the Woocommerce cart?
- How to get post’s current parent term ID?
- Adding Taxonomy Image to taxonomy loop [closed]
- Irregular TTFB and server wait time response
- get_the_title() gets printed out twice
- What does this mean in wordpress? Easy question
- How to get private property in parent class into extended class?
- Add Codepen animation as Preloader to WordPress
- Setting user nickname and displayname to shortened email
- Error Uncaught ArgumentCountError i cant find it
- Loop stopped working
- How does WordPress differentiate what scripts are loaded in wp_head() and wp_footer()?
- Download PDF after CF7 form submission
- Flexslider won’t work on WordPress
- Unable to Find Space in Custom Function
- Simple WordPress endpoint route doesn’t work
- Is it possible to create new user from external form using REST API?
- One account with multiple logins
- Comapare get_user_meta value
- How can get all users by current user meta?
- Sort posts in a specific way
- How to hide post in WordPress
- Only show posts from the last trailing 12 months
- `update_post_meta` not working anymore
- Custom pagination (Previous / Next)
- Getting the slug into a variable, how to echo that variable
- The user can only see their own profile
- Hide a div when a custom field is empty
- Post meta select input, if statement
- Fatal Error wp-settings.php on line 119
- what does $options = get_option(‘test_theme’); do?
- Set document title through shortcode plugin
- WordPress url By country code?
- How to change basename url for wp-admin?
- Prevent header and footer from loading on specific pages with template or plugin
- Weird fonts showing which are coming from database
- WordPress all php BUT index.php downloads instead of loads
- Don’t update modified post date when user add a product review or comment?
- Mysterious letters appearing at the top of a few pages
- Trouble matching strings (titles) using wp_query
- Current WordPress Page Title as Search Parameter into A Tag
- Limit the number of characters/words in an excerpt for a related posts section
- Yoast Breadcrumbs Inject Multiple Levels
- Maximum file Upload
- Customizer textarea with script tag won’t work in live preview
- How to give custom roles the capability to edit one Menu instead of every Menu
- Unzip_file causing Media file upload error
- Primary navigation menu with timed items from custom post type
- Styling a specific post after hovering over it
- WooCommerce – Add Shipping class below each product in Shopping Cart page
- WordPress file upload
- Escaping a Single Quote in str_replace for Nav Function
- Use fetch_feed(); Totally Outside of WordPress?
- widget: input the px value from user and use it as inline style in widget function
- Create a dynamic buddupress tab
- Setting pages for posts
- Problems with plugin that fetches data from database with ajax
- why is markup routinely placed in functions in wordpress?
- When I use rewind_post() it shows menu items in my loop
- Customise Author Page?
- How to create categories out of a list of words?
- Is there a way of displaying related posts from lowest hyrachical order (lowest child category to parent category)
- Difference between php memory limit and wp memory limit?
- SQL – How to echo out inside of where statement
- How to create different templates for woocommerce single-product.php?
- How can I update a value of a field depending on outside source?
- Restricting access to a file for everyone except logged in users
- WordPress Block Editor Gutenberg running code inside ! is_admin()
- Tags being Inserted in html from plugin PHP not passing through the_content