Hot answers tagged

21

Try adding this to your CSS file: body.admin-bar #branding-wrap{top: 28px;} body.admin-bar #wrapper{margin-top: 145px;} the body.admin-bardeclaration at the front will make sure that these styles only get applied when the admin bar is visible.


20

I would hook into the wp_head action. I would place this in a plugin so as to abstract it from your presentation layer. This allows for scalability and changing of themes. This also prevents any analytics collateral damage if a step is missed in migration from one theme to the next. add_action('wp_head', 'wpse_43672_wp_head'); function wpse_43672_wp_head(){ ...


15

you can change lots of things about the tinyMCE editor at the tiny_mce_before_init filter. http://codex.wordpress.org/TinyMCE_Custom_Buttons the following will restrict your blockformats to p,h3,h4 and blockquote function wpa_45815($arr){ $arr['theme_advanced_blockformats'] = 'p,h3,h4,blockquote'; return $arr; } add_filter('tiny_mce_before_init',...


15

Found the answer (via) Instead of using the function I added an action to "wp_loaded", that makes sure that it gets loaded before any headers are sended. <?php add_action ('wp_loaded', 'my_custom_redirect'); function my_custom_redirect() { if ( isset( $_POST['subscribe'] ) ) { $redirect = 'http://example.com/redirect-example-url.html'; ...


14

Here is the code I've used, based on the original question and on Dominic P's answer... /* * Modify HTTP header */ function add_header_xua($headers) { // var_dump($headers); #=> if you want to see the current headers... if (!is_admin()) { $headers['X-UA-Compatible'] = 'IE=edge,chrome=1'; } return $headers; } ...


13

This is typically caused by spaces or new lines before the opening <?php tag or after the closing ?> tag. Check out this page to see some solutions: How do I solve the Headers already sent warning problem? UPDATE After examining your plugin code, the one thing I noticed is that you don't have a closing PHP tag. On the last line, add ?>


11

I know it's been a while, but if anyone else stumbles on this, I found a WordPress hook specifically for modifying HTTP headers. The hook is wp_headers and it's called in the wp class. The first argument passed is an array of headers with the header name as the key. The second argument is a reference to the wp class object.


11

Looking at wp-includes/template-loader.php … there seems to be a way: if ( $template = apply_filters( 'template_include', $template ) ) include( $template ); You could hook into that filter, handle the including in a callback function and return FALSE. Sample code, not tested: add_filter( 'template_include', function( $template ) { get_header(); ...


11

If you link to the JS file just using something like //examplesite.com/js/jsfile.js without the http:// or https:// the browser should automatically get the correct http or https version


10

found solution: before wp_head() command, insert: remove_action('wp_head', 'rel_canonical'); p.s. if generator meta tag is being added from elsewhere (i.e. from theme or plugin, rather than wp-core) and was priority other than 10, then you might need to put the exact priority, as is was given from that theme/plugin: i.e. remove_action('wp_head', '...


10

Just add to your theme this code: <?php get_search_form(); ?> This code will echoing search form so place it everywhere where you want to have the search form. Further you need to have search.php file in your theme which will show the search results. You can use ordinary WP loop in the file.


10

Milo is correct. For instance, go to your theme's functions.php file, and add the following: add_filter( 'allowed_http_origins', 'add_allowed_origins' ); function add_allowed_origins( $origins ) { $origins[] = 'https://site1.example.com'; $origins[] = 'https://site2.example.com'; return $origins; } Now an ajax call from https://site1.example....


10

The output is generated by the rest_output_link_header(). This function is used in two actions, wp_head and template_redirect in default-filters.php:@line234. You can remove the function from those hooks to remove the output you wanted to remove. Put the following codes in your theme's functions.php to achieve the desired result. remove_action( 'wp_head', '...


9

The init action is the wrong place to do it. A better place would be at template_redirect, so that you only affect the front end view of the site and not the admin areas.


9

My guess is you get a PHP error, which generates output before the headers are sent. If you have E_NOTICE enabled, calling $_POST['foo'] may generate a "Notice: undefined variable" error if that variable is not set. Best practice: never assume anything about GET, POST, COOKIE and REQUEST variables. Always check first using isset() or empty(). if ( isset( $...


9

Try putting this snippet in your functions.php <?php function rel_next_prev(){ global $paged; if ( get_previous_posts_link() ) { ?> <link rel="prev" href="<?php echo get_pagenum_link( $paged - 1 ); ?>" /><?php } if ( get_next_posts_link() ) { ?> <link rel="next" href="<?php echo ...


9

There's a filter for that: function wpse_203745_wp_headers( $headers ) { $headers['Expires'] = gmdate( $somedate ) . ' GMT'; return $headers; } add_filter( 'wp_headers', 'wpse_203745_wp_headers' );


8

in your css you could try something like: body.logged-in{margin-top:20px;} or if this doesnt work some other code using the .logged-in class


8

add_action('wp_enqueue_scripts', 'no_more_jquery'); function no_more_jquery(){ wp_deregister_script('jquery'); } That will deregister jquery. But why wouldn't you want jQuery at all? If you mean to simply use your own, you should do it in that function, like this: add_action('wp_enqueue_scripts', 'no_more_jquery'); function no_more_jquery(){ ...


8

Ok so I think I figured it out... Both of these work for the most part as you'd expect by sending http / php headers to the browser. wp_headers is actually a filter inside the send_headers() functions.You can use this to modify the headers before they're sent to the browser with some exception. wp_headers won't be able to do anything if it's a static ...


7

The article on Ghacks is actually a pretty silly way to do it as well. The get_header() function is actually a pretty smart function. You can do some neat things with it. For example, you can do this: get_header('category'); That will cause it to load the header-category.php file, if such a file exists, or the header.php file, if header-category.php does ...


7

BODA82's answer helped, but eventually I realized that I should have replaced responseText with responseJSON method in my JavaScript code. In the example below I was storing the Ajax response results in a variable. I didn't know there was a specific method to get the response in JSON. In a such way the object/array with get_posts() results is returned ...


7

The proper way to send a status (when WordPress is not available) is: http_response_code( 403 ); See the PHP Manual for its definition. But in Plugin files, this should never be the "default" code on top of a file header. See Worthwhile to restrict direct access of theme files? for a discussion. In WordPress, use status_header( 403 ) if you need it. A ...


7

<?php add_filter('after_setup_theme', 'remove_redundant_shortlink'); function remove_redundant_shortlink() { // remove HTML meta tag // <link rel='shortlink' href='http://example.com/?p=25' /> remove_action('wp_head', 'wp_shortlink_wp_head', 10); // remove HTTP header // Link: <https://example.com/?p=25>; rel=shortlink ...


6

get_header( $name ) is a Wordpress function, that will try to load the file header-{$name}.php from your theme's root folder. If this file doesn't exist, Wordpress will load the default header.php file.


6

That's an old question, here is another and easy solution for WORDPRESS MULTISITE MENU sharing across all network sites, Not only menu you can use the same method to share anything other then widgets across all the network sites. here is the solution : Edit your Header.php //store the current blog_id - Use this function at the start of the function that ...


5

Put the code inside a file named your_name.js. Add the following to your functions.php file: function wpse47618_load_script_last() { wp_enqueue_script( 'zzz_your_name', get_stylesheet_directory_uri().'your_name.js', array( 'jquery' ), '0', true ); } add_action( 'wp_enqueue_scripts', 'wpse47618_load_script_last', 99999 ); Check your pages source code if ...


5

The in_admin_header action may be used to insert content before <div id="wpbody"> in the wordpress backend. See Line 101 of /wp-admin/admin-header.php (line number as of version 3.3.2) Further reading on actions: Action Reference, codex


5

WordPress offers the function status_header() to return the correct status-code. You can call this function inside your WordPress template/function: // Will return http status header "200 OK" status_header(200);


5

Wordpress provides a way to prevent the header HTML from being rendered, by appending &noheader=true to the url. That will cause the header HTML to wait for you to call it manually, so that you can do a redirect before that. To later render the header HTML from your page, you'll have to use this: if ( isset($_GET['noheader']) ) { require_once(...


Only top voted, non community-wiki answers of a minimum length are eligible