Correct way to enqueue page specific CSS file

So this way a CSS file would be enqueued in the header.php and then another in that specific page.php. No because: all the things that get enqueued are processed in the header but you’re calling it after the header has already been done. The cat has already gotten out of the bag, the horse has … Read more

Converting Y-m-d to a date with a Month name? [closed]

You can use createFromFormat to re-format your date. Like so: $date = DateTime::createFromFormat(‘Y-m-d’, ‘2021-12-06’); echo $date->format(‘Y F d’); If you want your output to be anything other than “2021 December 06”, please check PHP datetime formats for all available formatting options.

Returning data instead of echoing/printing

The problem with your code, as you mentioned, is that you are outputting the images via your print_r function, and you need to instead build a string to return, which is displayed in place of the shortcode. Give this a try: function get_media () { $attachments = get_posts([ ‘post_type’ => ‘attachment’, ‘numberposts’ => -1, ‘post_status’ … Read more

Asynchronous multiple requests 401 Unauthorized

Apparently, this already is a known issue on GitHub. Still open and not patched from May 16, 2016. Based on the suggestion from the comments, creating a new Hooks instance and registering the hook curl.before_multi_add with a callback that sets the cURL authentication options should solve the [401] Unauthorized Access problem. use WpOrg\Requests\Hooks; $hooks = … Read more

Why am I getting a different filename? And how does WordPress load singular.php for both Page & Post? (Fresh WordPress installation)

This is because you did not put singular.php in the URL, and if you did it wouldn’t make any sense. Remember, WordPress loads the template, not the other way round, your mental model of how this works is upside down. What’s going on? Why is singular.php the file being accessed while PHP prints that the … Read more

Custom PHP script throws critical error ONLY when editing page

When you’re editing the page, you’re in the directory wp-admin, and wp-admin doesn’t contain wp-content (they’re both children of your site’s root directory). Instead of ‘wp-content/uploads/cams/’, I’d recommend ABSPATH . ‘wp-content/uploads/cams/’ which should work wherever you might be in the WordPress environment.

Why is $wp->request empty in WordPress 6.0?

What is the correct way in WordPress to obtain the current page url? You don’t, WP has never provided a way to do this, the closest is get_permalink which provides the canonical URL of the current post. What you’ve been using is unofficial, and never gave you the actual URL as it only appended the … Read more

Warning: Attempt to read property “ID” on null in D:\xampp\htdocs\yba\wp-content\themes\young-brand-child\functions.php on line 162 [closed]

I’m guessing the problem is here: $pg_name = apply_filters( ‘the_title’, $item->title, $item->ID ); $page_id = get_page_by_title( $pg_name ); $item_output .= ‘<a’. $attributes .’ id=”‘.$page_id->ID.'”>’; I don’t think this makes any sense: you have the item title and ID you’re filtering the title and then you’re trying to look up the page ID again by the … Read more