Skip to main content
28 votes

Adding javascript to child theme

You should enqueue the script in child theme's functions.php. for example if name of the js file is custom.js and if you place it under js folder in your child theme, then in functions.php you should ...
Akshat's user avatar
  • 1,197
18 votes

Is there a way to enable Cross-Origin Resource Sharing for WordPress' ajaxurl?

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 ) { ...
Julian's user avatar
  • 289
14 votes
Accepted

Remove rel=shortlink from HTTP header

<?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=...
Max Yudin's user avatar
  • 6,318
11 votes
Accepted

Clarity needed on usage of multiple 403 forbidden header() functions at the beginning of the plugin files

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 ...
fuxia's user avatar
  • 107k
10 votes
Accepted

Cannot load admin-ajax.php. No access-control allow origin*

There are filters for allowed_http_origins and add_allowed_origins. You can use them to set the proper Access-Control-Allow-Origin header in the response to your AJAX call. Add this to your theme's ...
ben's user avatar
  • 116
10 votes
Accepted

How can I change HTTP headers only to posts of a specific category from a plugin

Why it doesn't work: send_headers hook is fired once the HTTP headers for caching, content etc. have been sent, but before the main query is properly initiated. That's why in_category() function doesn'...
Fayaz's user avatar
  • 8,937
10 votes
Accepted

Custom endpoint and X-WP-TotalPages (headers)

I had a quick look and here's how the headers are set in the WP_REST_Posts_Controller::get_items() method: $response = rest_ensure_response( $posts ); // ... $response->header( 'X-WP-Total', (int)...
birgire's user avatar
  • 67.4k
8 votes

wp_redirect() - headers already sent

you can also do this Instead of the below line wp_redirect("$url"); write echo("<script>location.href = '".$url."'</script>"); or <?php <script><?php echo("location.href =...
Mohammad Zaer's user avatar
7 votes

Sharing Header Components Across Multisite

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 ...
Muhammad Abdullah's user avatar
6 votes

Why is there a link tag with rel "profile" pointing to gmpg.org?

This profile enables your site to use the FOAF semantic insertions for richer metadata on your site. FOAF goes for Friend Of A Friend and aims to interconnect in "knowledge nodes" all the personal ...
Ricard Menor's user avatar
6 votes

How do I make my plugin load before the headers are output so I can redirect wordpress?

The correct hook to use is template_redirect which allows you to have the necessary info available to do checks while also early enough to actually redirect. As per the example on the codex page: ...
Ashraf Slamang's user avatar
6 votes
Accepted

'Headers already sent' Error When Redirecting from add_submenu_page() Callback

Background The infamous "Headers already sent" error rears it's ugly head in circumstances where something attempts to modify the HTTP headers for the server's response after they have ...
bosco's user avatar
  • 6,815
6 votes
Accepted

Is it safe to fix Access-Control-Allow-Origin (CORS origin) errors with a php header directive?

Yes, you open your site to being requested via AJAX to any other script in the whole web. It would be better if you limit the origin to one specific remote domain from which you are consuming the API,...
Jesús Franco's user avatar
6 votes
Accepted

Is_front_page inside header.php is always returning true

Yes it should work in the header file just like normal. Try using a standard IF statement instead of shorthand: if( is_front_page() ){ echo 'Front page!'; } You must have it configured in the ...
sMyles's user avatar
  • 2,836
6 votes
Accepted

How to remove X-Frame-Options: SAMEORIGIN" from WordPress?

Check this question How does wordpress restrict X-FRAME to sameorigin?. The questioner's issue was resolved by modifying his site's .htaccess file by adding the below line to it as his Web Host set ...
Anteraez's user avatar
  • 109
6 votes
Accepted

wp_redirect() doesn't work

The problem is not what you are doing, but when you are doing it. When your browser requests a webpage, that webpage arrives with a set of HTTP headers, followed by a HTTP body that contains the HTML. ...
Tom J Nowell's user avatar
  • 59.6k
5 votes
Accepted

How to load a different header based on post format?

Say if your have header-video.php used for video post format. Replace get_header(); with get_header(get_post_format()); in your regular singular.php or index.php. If WP can find header-video.php it ...
Z. Zlatev's user avatar
  • 1,149
5 votes
Accepted

add styles if custom header was included

get_header has an action hook called, (surprise!) get_header which gets a single parameter - the name of the header file. So what we do is check that name and if it matches our name we add a style. So ...
kraftner's user avatar
  • 5,608
4 votes
Accepted

StudioPress: add meta tag to every page

This function should take care for the input into the head of each page/post as asked. Please make a copy of functions.php before adding following code.Adjust to your own preferences if needed. /**...
Charles's user avatar
  • 2,287
4 votes

In a WordPress plugin, how do you output HTML code inside the DOM header?

You can add html to the site head using this function: // Add scripts to wp_head() function add_head_html() { ?> <!-- html goes here --> <?php } add_action( 'wp_head', '...
Monkey Puzzle's user avatar
4 votes
Accepted

Remove link around logo

Look at the documentation for the_custom_logo(): Displays a custom logo, linked to home. So it's doing what it's supposed to. If you want to do anything other than that, you can get the ID of the ...
Jacob Peattie's user avatar
4 votes
Accepted

"Cannot modify header information" means I can't use wp_redirect

As Milo stated, you can't send header information after PHP has begun sending request response body. Redirects belong in a function hooked into wp_loaded to ensure they run before the request body is ...
Gray's user avatar
  • 324
4 votes
Accepted

Disabling the X-Redirect-By response header

This line added to functions.php (ideally in a child theme, or a plugin) will remove it: add_filter( 'x_redirect_by', '__return_false' );
Jacob Peattie's user avatar
4 votes
Accepted

Does wordpress templates always in files or in database?

But there is no content directory in template directory. Actually, with the following: get_template_part( 'templates/content', 'header-private' ); get_template_part( 'templates/content', 'header-...
Sally CJ's user avatar
  • 39.3k
3 votes

How do I make my plugin load before the headers are output so I can redirect wordpress?

How about using this action? Codex Link - send_headers action add_action( 'send_headers', 'add_redirect_header' ); function add_redirect_header() { header( 'Location: http://www.google.com' ); }
juz's user avatar
  • 151
3 votes

Is there a way to enable Cross-Origin Resource Sharing for WordPress' ajaxurl?

Just add this code into your function.php, no need to update .htaccess, /wp-includes/http.php or any other core file. function just_add_cors_http_header($headers){ $headers['Access-Control-Allow-...
Ali Raza's user avatar
  • 131
3 votes

Different custom header image on different page

create new file in your theme with name header-custom.php next copy this code into that file class customheaderMetabox { private $screen = array( 'post', 'page', ); ...
Manyang's user avatar
  • 107
3 votes
Accepted

How to remove/hide action links cluttering under specific plugins' names

You have the right approach. You will want to use the admin_enqueue_scripts hook: add_action( 'admin_enqueue_scripts', 'wpse_239302_hide_action_links' ); function wpse_239302_hide_action_links() { ...
Ethan O'Sullivan's user avatar
3 votes

Creating a WordPress form with a PHP script and default header

Firstly, never send the browser directly to a PHP file in your theme or plugin. It's a security hole and leads to a very fragile setup. For example: The file will work even if the theme is ...
Tom J Nowell's user avatar
  • 59.6k
3 votes

How do I get my main image to stretch the full length of the screen?

You learned a valuable lesson: do not mess with the original theme files. Learn how to build a child theme and you will always be able to return to the original, working theme if any accidents happen. ...
cjbj's user avatar
  • 14.6k

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