Use wordpress functions in another PHP file

You must put your gallery.php in the same theme folder, where the theme’s functions.php resides. Then add a single line in functions.php: get_template_part(‘gallery’,”); It’ll include the gallery.php file into functions.php and gallery.php will behave like functions.php. So, you have to keep in mind that, functions.php file is a file for WordPress and PHP functions. So … Read more

Issue using wp-load.php in WordPress Plugin Development

The problem in this solution is, that the location of this file are different. WordPress allow the definition of the folder of plugins and themes, different to your static path check for the wp-load.php. Example for custom paths //* // Custom content directory define( ‘WP_CONTENT_DIR’, dirname( __FILE__ ) . ‘/wp-content’ ); define( ‘WP_CONTENT_URL’, ‘http://’ . … Read more

wp-load.php not working

You don’t need to load wp-load.php, you can build an endpoint to poll with javascript using a REST API endpoint. In your plugin, or functions.php, we’re going to create an example endpoint, it will live at https://yoursite.com/wp-json/yourname/v1/yourendpoint, it will take in parameters, and reply with a snippet of JSON, just as you would expect from … Read more

Check user logged in from outside of WP folder

If WordPress is installed in /subfolder/, then the authentication cookies will by default only valid for that path. So if needed, you can allow the cookies in parent directory by setting the cookie constants like COOKIEPATH. For example, if I had WordPress installed at example.com/wp/ and I wanted the authentication works at example.com/, then I’d … Read more

Open Post Thumbnail in New Child Theme File in WordPress

As mentioned in the comments, neither single-thumbnail.php or single-ad.php will work in a simple manner. Sure a complex solution/workaround could be written but it’s totally unnecessary. The template hierarchy in WordPress doesn’t work that way. Whatever follows single- in a single-XXXXX.php file is used to denote the content type/post type. So the single-ad.php would only … Read more

Include CSS with PHP without including wp-load?

EDIT Forget my answer below. You could simply use wp_register_style and wp_enqueue_style described in this answer. You could do it with an additional query variable. Add a new variable to the $query_vars array with the query_vars filter On the template_redirect action, make sure your custom.php-css file is included, if the query variable is set. // … Read more

Best way to load WordPress Bootstrap

Requiring a file using relative path is never a good idea, that because wp content folder can be easily changed and that make your code fail. You should convert your file into a MU plugin (you only need to save it wp-content/mu-plugins folder) and change it to something like: add_action( ‘wp_ajax_super_custom_stuff’, ‘my_super_custom_stuff’ ); add_action( ‘wp_ajax_nopriv_super_custom_stuff’, … Read more

How to avoid loading wp-load.php from external php scripts?

Pretty much wp-load.php is the only way to go. I don’t think there is really another way to load the WordPress functions safely… You can account for path variations by recursively including it from any file where you need it though… eg. function file_find_require($file,$folder=null) { if ($folder === null) {$folder = dirname(__FILE__);} $path = $folder.DIRECTORY_SEPARATOR.$file; … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)