Reading the inside of

If you’re in the admin and you want to “read” the <head /> of the frontend, you can make an internal HTTP request and scrape the response HTML: $url = home_url(); $request = wp_remote_get( $url ); $body = wp_remote_retrieve_body( $request ); $dom = new DOMDocument(); libxml_use_internal_errors( true ); $dom->loadHTML( $body ); $xpath = new DOMXpath( … Read more

How to add css to wp_head depending on the user role?

Thanks to the help of two fellow members of this forum I have managed to get the snippet working. Here I leave the solution for any future answer seeker who happens to stop by. add_action( ‘wp_head’, function () { //Get current user ID, if the user is logged in. if ( is_user_logged_in() ) { $user_id … Read more

Use WordPress Built In Jquery

The jQuery object is jQuery rather than $. See noConflict wrappers in wp_enqueue_script for some examples. jQuery(document).ready(function($) { // Inside of this function, $() will work as an alias for jQuery() // and other libraries also using $ will not be accessible under this shortcut });

Head Code for Custom Taxonomy

In this case you just need a conditional tag inside of the wp_head action. Placing the following on your functions.php will solve the problem: add_action( ‘wp_head’, ‘q166556_taxonomy_head’ ); function q166556_taxonomy_head(){ // Conditional for Taxonomy archives and posts that have any term from the taxonomy `store` if ( ! has_term( ”, ‘store’ ) && ! is_tax( … Read more

Adding a wp_head hook from an included PHP file

To enqueue styles and scripts properly, use the wp_enqueue_scripts action like so: function wpa_63708_enqueue_scripts() { wp_register_script( ‘my-script’,’/path/to/script’ ); wp_enqueue_script( ‘my-script’ ); } add_action( ‘wp_enqueue_scripts’, ‘wpa_63708_enqueue_scripts’ );