Hot answers tagged urls
13
From my experience and quick code search there are no deliberate ways WP identifies itself in headers. However there are some that seem distinct enough and not likely to be customized.
HEAD to /wp-login.php will contain following for .org install:
Set-Cookie: wordpress_test_cookie=WP+Cookie+check; path=/
And for .com:
Set-Cookie: ...
11
Send a HEAD request to /wp-feed.php in the same directory as /xmlrpc.php (even in subdirectory installations). In WordPress you will get a Location header as response containing the string feed.
In your example for blog.stackoverflow.com you’ll get:
HTTP/1.1 301 Moved Permanently\r\n
Date: Thu, 07 Jun 2012 07:30:10 GMT\r\n
Server: Apache/2.2.9 (Ubuntu) ...
6
Append the URL with ?page_id=-1 and do an HTTP HEAD request for that.
On self-installed WordPress blogs, this will result in a 404 response.
On wordpress.com blogs, this will result in a 301 response (which ends up at a 200 response if you follow the redirect).
On non-WordPress sites, you should get a 200 response (assuming the original URL without the ...
5
The answer above seems comprehensive, but I just wrote a wrapper function and moved on. Here it is if you need it (put this in functions.php):
function get_avatar_url($get_avatar){
preg_match("/src='(.*?)'/i", $get_avatar, $matches);
return $matches[1];
}
and then use it wherver you need it in the template files like this:
<img src="<? echo ...
5
Less than an answer, but just a list of things straight from my experience with it - maybe you've overlooked something.
Debugging the request & its results
Without diggin' too deep into the update process, but the WP HTTP API uses the WP_HTTP class. It also offers a nice thing: A debug hook.
do_action( 'http_api_debug', $response, 'response', $class, ...
5
You can turn your snippet into a function that returns the post thumbnail URL of a post:
function wpse81577_get_small_thumb_url( $post_id ) {
$thumbSmall = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'small' );
return $thumbSmall['0'];
}
Usage, supplying the ID of a post:
<?php echo wpse81577_get_small_thumb_url( 59 ); ...
5
It is okay that the URL changes to http://mysite.com/contact/#rocket, but you should change the way you are defining your anchor on the target page.
Instead of using this method
<a name="rocket"></a>
<div>
<h3>The Title</h3>
<p>some text</p>
</div>
You should add an ID to the content you want to jump to ...
4
another option - redirect /admin/ to wp-login.php with a parse_query action hook:
function wpa53048_parse_query( $query ){
if( $query->query_vars['pagename'] == 'admin' ):
wp_redirect( wp_login_url() );
exit;
endif;
}
add_action( 'parse_query', 'wpa53048_parse_query' );
EDIT
Well the above apparently only works with certain ...
4
This seem to work:
Create the rewrite rules like post-type/post-name.html. You can use arrays to create the rules for just some set of post types instead of doing it for all of them.
add_action('rewrite_rules_array', 'rewrite_rules');
function rewrite_rules($rules) {
$new_rules = array();
foreach (get_post_types() as $t)
$new_rules[$t . ...
4
Short Answer
example.com/bob/files/picture.jpg is the preferred, canonical URL for images in a WordPress Multisite installation. The two URLs with blogs.dir in the URL are essentially identical, and both leverage the filesystem structure. The path with 'bob' exists because you did a sub-directory install, not a subdomain install. Other paths would exist ...
4
I'm not sure this question is WordPress-related. It sounds like it might be handled via .htaccess redirect, or a browser extension.
That said: you could try to use the wp_get_attachment_url filter, that is applied to the URL returned by wp_get_attachment_url().
For example:
function wpse95271_filter_wp_get_attachment_url( $url ) {
if ( 0 === stripos( ...
3
I'm generating my CSS dinamically in a function...
If so, great! You should just need to hook the output of that function into the 'wp_print_scripts' action hook, like so:
function wpse59089_dynamic_css() {
?>
<style type="text/css">
<?php
// Dynamic CSS goes here
?>
</style>
<?php
}
add_action( 'wp_print_scripts', ...
3
Neither is wp-super-cache available on all wordpress installations, nor is there any fixed format in the URLs. While the permalinks settings page do give some fixed settings for URL schemes which can be used, anyone can just use any custom URL scheme. For example, if anyone just decides to use only the page/post name in the URL, it is more or less ...
3
Because the tag query variable expects the value to the terms slug. It'll be looking for the term with slug '15' (which presumably doesn't exist).
And, yes its quite frustrating that wp_dropdown_categories() uses the ID as the value, rather than the slug. This is because it was originally used only for categories (for which IDs rather than slugs are ...
3
add
'rewrite' => array('slug' => 'portfolio-categories'),
but be sure to remove (not sure why that's there, it tries hides the slug yet tries to rename it to "products" at the same time?):
'rewrite' => array( 'with_front' => false, 'slug' => 'products' ),
So it looks like this:
function mysite_post_types() {
...
3
WordPress has a built-in function for removing protocol and domain from absolute URLs, wp_make_link_relative, located in /wp-includes/formatting.php:
function wp_make_link_relative( $link ) {
return preg_replace( '|https?://[^/]+(/.*)|i', '$1', $link );
}
To apply this function to (e.g.) permalinks, simply add a filter, as such:
add_filter( ...
3
You should be using a filter outside of your template for this:
add_filter( 'template_include', 'wpa62226_template_include', 1, 1 );
function wpa62226_template_include( $template ){
if( is_page( 'some-page' ) ) :
global $wp_query;
$wp_query->set_404();
status_header( 404 );
$template = locate_template( '404.php' );
...
3
You can do this with a rewrite rule from within WordPress. Take a look at the documentation for add_rewrite_rule.
Something like this:
<?php
add_action('init', 'wpse65855_rewrite');
function wpse65855_rewrite()
{
add_rewrite_rule(
'^photos/?$', // the rule regex
'index.php?taxonomy=category&term=photos', // where you want the ...
3
You need to start your links with http://
Examples:
The link facebook.com/mypage becomes http://facebook.com/mypage
The link www.commentorsite.com/ becomes http://www.commentorsite.com/
This will stop the links becoming http://mysite.com/www.commentorsite.com/ or http://mysite.com/facebook.com/mypage
3
Filter category_link so WordPress creates slashed URLs for categories, and redirect_canonical so it accepts those URLs:
add_filter( 'category_link', 'wpse_71666_trailingslash_cat_url' );
add_filter( 'redirect_canonical', 'wpse_71666_trailingslash_cat_url', 20, 2 );
function wpse_71666_trailingslash_cat_url( $url, $request = '' )
{
if ( 'category_link' ...
3
Based on @kaiser’s useful answer I have written some code that seems to work well. That is the reason why I marked it as The Answer.
Let me explain my solution …
The logic
When a request it sent through the API is runs through WP_Http::request(). That’s the method with …
@todo Refactor this code.
… in its header. I couldn’t agree more.
Now, there ...
3
Off the bat, I can't give you a page/tutorial/documentation on how WP slugs are generated, but take a look at the sanitize_title() function.
Don't get a wrong impression by the function name, it is not meant to sanitize a title for further usage as a page/post title. It takes a title string and returns it to be used in a URL:
strips HTML & PHP
strips ...
3
It happens because when you save a post, WordPress calls sanitize_title function to sanitize your title. This function applies sanitize_title filter.
One of core hooks for sanitize_title filter is sanitize_title_with_dashes function, which checks title on utf8 format by calling seems_utf8 function and if the title has utf8 format, the function call ...
3
You can do this by adding this function to your funcitons.php file.
function my_get_image_size_links() {
/* If not viewing an image attachment page, return. */
if ( !wp_attachment_is_image( get_the_ID() ) )
return;
/* Set up an empty array for the links. */
$links = array();
/* Get the intermediate image sizes and add the full size to the array. */
...
3
I believe that is the redirect_canonical function hooked to template_redirect. You should be able to disable it with:
remove_filter('template_redirect', 'redirect_canonical');
But you should really think about whether you want to do that as it is fairly complicated and performs some important SEO functions:
Redirects incoming links to the proper URL ...
3
I have written a solution for that some time ago:
<?php # -*- coding: utf-8 -*-
/**
* Plugin Name: T5 Comment author URI to blog author page
* Description: Changes the comment author URI to the blog’s author archive
* Version: 2012.07.18
* Author: Thomas Scholz
* Author URI: http://toscho.de
* License: MIT
* License URI: ...
3
You are in the wrong settings page. Your site is a multi-site setup; the URL is set in the site manager, not in individual sites.
Go to Network Admin/Sites in the My Sites menu:
Select a site to edit:
Change the URL:
Update
You need a subdomain setup to get editable URLs.
See Create A Network for the installation guide and Configuring Wildcard ...
2
Ok so apparently this site is behind a firewall or proxy.
On lines 491 and 658 in wp-admin/includes/class-wp-list-table.php, replace this line $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
with
if(!empty($_SERVER['HTTP_X_FORWARDED_HOST'])){
$hostname = $_SERVER['HTTP_X_FORWARDED_HOST'];
} else ...
2
You should be able to get the current url from $url = add_query_arg().
Then assuming, the structure: www.example.com/page/subpage/news/ID/post you can use preg_match to extract /page/subpage/news. Then it would be simple matter of using get_page_by_path();.
If that fails you can then check /page/subpage/ and finally /page.
2
Oops... just found how, by reading the source:
get_term_feed_link( $my_custom_taxonomy_term->term_id, 'my_custom_taxonomy_name' );`
It's just not documented in the Codex.
Only top voted, non community-wiki answers of a minimum length are eligible