WordPress wp_loaded action hook

wp_loaded is called long, long before the post content is fetched. Put that code into a plugin. Also, you shouldn’t echo anything that early. The HTTP headers aren’t sent yet on wp_loaded, so you will get the Headers already sent error, and your user authentication will not work: you cannot log in anymore.

Where Are Hooks?

Hooks/actions are better thought of as events. When you run this code: add_action( ‘post_footer’, ‘toms_footer_stuff’ ); You’re saying that when the post_footer event happens, run the toms_footer_stuff function. These functions take the form of: add_action( name_of_action, php_callable ); A PHP callable is something that can be called represented as an object. It can be any … Read more

Redirecting from login

There’s a filter called login_redirect. add_filter( ‘login_redirect’, ‘wpse377295_login_redirect’, 10, 3 ); function wpse377295_login_redirect( $url, $request, $user ) { if ( is_wp_error( $user ) ) { // It’s possible that the $user param is a WP_Error. If so, bail out. return $url; } if ( ! user_can( $user, ‘update_core’ ) { // Only admin users can … Read more

wp_enqueue_script before wp_head

Enqueue mechanics and suggested ways to use them serve flexibility and interoperability. Simply put consider what would be the easiest way for third party code to modify mechanics of yours? Hardcoding things in template often makes editing that template the only viable option. Manipulating hooks is typically more convenient and less problematic than that. On … Read more

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