insert in the head tag after wp_head - wordpress

Using wordpress 2.9.2. I am loading my css files for plugins as they are being called, which ofcourse is after my header has been loaded. I want to insert the calls those css files in the HEAD tag of the page, which can be done if i get a hook which includes lines in the head after wp_head() has been called. Help !

Look at http://codex.wordpress.org/Plugin_API/Action_Reference/wp_head - the action is called wp_head.
You will want to use wp_register_style() to register your CSS file followed by wp_enqueue_style() to actually add it to the list of stylesheets that are output.
There is an example on that page, but replace 'wp_print_styles' in the example with 'wp_head'.

Have you tried echoing the styles or .css include the in a function passed into wp_print_styles API action hook?

If you are using your own theme, you can just put <style> tags in your header.php file pointing to the stylesheets you are using.
If you need a hook, it is called wp_head (check the Codex documentation on it).

The solution that worked for me was inserting the css files in head using output buffer.

Related

Add comments to wordpress inspect element page

As the title says, I want to add some sort of signature with comments on my wordpress index file, thing is - there are 30 different index files and none of them seems to work
If I understand correctly, it'll just be a case of adding some HTML comments (not PHP comments as they won't show in the source code) in your theme files. Bear in mind that editing a theme won't work if someone else made it and releases updates to it as it'll overwrite your changes if you update it.
The best place to add in the comments is to either open the header.php file and place your HTML comments after the opening <body> tag. If your theme doesn't include a header file, you could always add your comments to the top of your themes index.php file instead.
Your theme should be located within /wp-content/themes/YOUR-THEME/.
Alternatively, you could also place HTML comments between the <head> tags of your theme so they show up a bit higher in the source code. To do this, it's probably best to use an action hook instead. Place this in your themes functions.php file:
add_action( 'wp_head', 'add_signature_to_theme', 1, 0 );
function add_signature_to_theme() {
?><!-- Welcome to my website. --><?php
}
The wp_head action hook documentation is useful to have as reference as well if you'd like a bit more information on what it is and what it does.

WordPress Template "X": Change html inside of <head>

I'm pretty new to WordPress and want to remove some unneeded js/css files that are loaded inside of the html-head of the page.
In wp-content/themes/x/framework/views/header/base.php I found the following code:
<head>
<?php wp_head(); ?>
</head>
This obviously doesn't help me at all. I have no idea what WordPress' "wp_head()"-function does next. Isn't there some simple file where I can just write/edit simple HTML for the "head" somewhere?
wp_head() is a function that fires the wp_head action hook. Wordpress is built on action hooks and filters, which means that not only can plugins and themes add things to your setup through these hooks, but you have the ability to remove things as well. Most of this is done programmatically (in PHP) instead of there just being an html template, although that's not always the case... but it IS the case in your case.
Scripts and styles, for the most part, are enqueued through the wp_enqueue_scripts action hook. You'll want to perform your script removals here.
The problem is, you'll have to know the name the script was registered as before you can remove it. For instance, jQuery is registered as 'jquery'. Pretty simple, right? However, not all scripts are going to be that simple, and you'll have to browse through the code to find the registered handles (names) for those scripts. Styles are a bit easier, as when you inspect your page in the browser, styles will have an id attribute set to 'example-style-css'. Wordpress appends the '-css' to registered and enqueued styles, so the name of your style is actually 'example-style'.
In your theme's functions.php, you can dequeue scripts and styles so they won't be included on your page like so:
function stack_46669800_dequeue(){
wp_dequeue_script('the-script-you-want-to-remove');
wp_dequeue_style('the-style-you-want-to-remove');
}
add_action('wp_enqueue_scripts','stack_46669800_dequeue',100);
(Notice the 100 in the add_action function here... This is the 'priority', or the order in which all added actions are fired. Most are at 10, so I changed the priority here to 100 so this would be fired presumably later than whatever is enqueueing your unwanted scripts. You can't dequeue something that hasn't been enqueued yet.)

More Than One OG URL Specified and only Yoast graph is open not Jetpack

I'm having some problem with the od: tags which is the most common issue.
Only Yoast is active for open graphs not Jackpack publicize and then how the og: tags are showing in the header of the page as shown above in the image.
would be grateful if anyone can help
There can be two possibilities:
The other og tag is printed in theme's header.php. If it's there then comment that code and you're good to go.
The OG tag is being generated by some function hooked to wp_head hook. Now it can be anywhere, in any file in plugin or theme. The best approach would be to check all the hooked functions for wp_head hook. You can do so by this code:
add_action("wp", function(){ print_r($GLOBALS['wp_filter']); echo '';exit; } );
Write this code in functions.php of your theme and look for all the functions which are hooked with wp_head hook. You can then comment the code in that particular function.
It is possible that your template adds the additional og:url header (from your page source it appears so). You need to disable the additional headers using either a switch in template settings or by manual edit.

Inject code to the <head> tag of the TinyMCE iframe on WordPress

Is it possible to inject code to the TinyMCE WordPress editor via hooks? Specifically, I want to insert code within the <head> tag of the <iframe>. Something similar to the add_action( 'wp_head', 'function_name' ).
The content I'll add is a dynamically generated CSS (based on an ACF Options Page repeater field). I tried to create a *.php file with header("Content-type: text/css") header in it + the CSS content and then use the add_editor_style() function but when I call the file in a href attribute it seems like the WordPress functions (including ACF's get_field()) are not defined.
I also tried using data URI strings like data:text/css,.color_1{color:... but add_editor_style() ignores invalid URLs.
There are two settings in the TinyMCE configuration that you can use to pass CSS to the editor:
content_css
https://www.tinymce.com/docs/configure/content-appearance/#content_css
content_style
https://www.tinymce.com/docs/configure/content-appearance/#content_style
You can use the tiny_mce_before_init filter (via add_filter) to inject CSS into the editor using one of these configuration options.
As a WordPress plugin would be running in PHP perhaps you could process the needed CSS into a string on the server and pass it in via content_style?

Including CSS in my plugin shows up in source but does not apply to my elements

I'm including a .css file in my plugin and the files show up on my page and I can see the path and click through the path to see the raw .css content. However, It is not applying to my HTML elements.
I removed the wp_enqueue_style() that included my CSS file in my plugin and placed the code in my theme's custom CSS template I'm using (just the raw css) and refresh and that works; the CSS is applied to my HTML elements as expected.
One thing to note is that in the same plugin I'm returning HTML that I want this CSS to be applying to through a shortcode on a page.
Is it something with the CSS not being registered/applied in time to pick up or find the elements if it's adding from a plugin? I need the CSS to be added from the plugin and not from the theme's template. Is there something I'm missing?
Thanks!
I figured out my own problem.
My plugin code was:
wp_enqueue_style('nbfx-fs-css', plugins_url('/assets/css/nbfx-fs.css', __FILE__), array(), null, true);
I took a look at my HTML source and found this:
<link rel='stylesheet' id='nbfx-fs-css-css' href='MY-CORRECT-CSS-FILE-PATH' type='text/css' media='1' />
And I noticed the media='1'. So apparently I need to leave the 4th parameter blank or provide 'all'.
I hope this helps someone else who copy and paste the wp_enqueue_style() function with set parameters from someone else.

Resources