Tag Info

Hot answers tagged

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: ...


12

There's actually a great function that will do all three of those things for you: media_sideload_image( $url, $post_id, $description ); The first argument is the remote url of the image you want to download. The second argument is the post id of the post to which you want to attach the image. The third argument is optional, but will be a description if ...


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) ...


11

You are asking two questions at once: What's the difference between home_url() and site_url()? How do I get WordPress to return the URL root without the subdirectory where it's installed? Here are the answers, and I confirmed with Andrew Nacin, a core developer of WordPress, as well as ran some server tests to confirm what Andrew told me. Question # 1 ...


10

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 ...


9

I would use the wp_title filter hook: function theme-slug_filter_wp_title( $title ) { if ( is_404() ) { $title = 'ADD 404 TITLE TEXT HERE'; } // You can do other filtering here, or // just return $title return $title; } // Hook into wp_title filter hook add_filter( 'wp_title', 'theme-slug_filter_wp_title' ); This will play ...


9

Does WP keep track of a posts url history, providing rewrites/redirects for former urls? Yes it does. If you change a post slug, wordpress 301 redirects the old to the new URL (if your server setup allows it). Any light on how WP handles this would be appreciated. Unfortunately, I've never seen this feature properly documented in the codex. Hence ...


9

Symbolic links are … risky in WordPress. It is easier to use a separate domain for plugins per wp-config.php: define( 'WP_PLUGIN_DIR', '/local/path/to/plugin/directory' ); define( 'WP_PLUGIN_URL', 'http://plugins.dev'); See Strategy On Building Plugin Using Eclipse as an example for IDE configuration with such a setup.


8

You can add this in your functions, and it will rewrite the slug from default "author" to "classroom", function new_author_base() { global $wp_rewrite; $author_slug = 'classroom'; $wp_rewrite->author_base = $author_slug; } add_action('init', 'new_author_base'); hope it helps you


7

When you don't know if query string was started or not you can use add_query_arg which it knows how to deal with that and adds the "?" or "&" marks (which ever one is needed) to the query string. Update By popular demand I'm adding a few examples that are from the codex: Using get_permalink: Since get_permalink() returns a full URL, you could ...


7

This thing you are saying is unwanted is just normal functionality under WordPress and it cannot be removed. However there are things you can do to point the unwanted URL to something more usefull. Here is a forum post on this issue with some interesting fixes and a description on what is happening: ...


6

It's a sign that you have ALTERNATE_WP_CRON defined in your wp-config.php In order to do some background processing (like publishing scheduled posts), WordPress redirects you to the URL with ?doing_wp_cron appended.


6

You could do this on custom post type registration. 1) Set your default permalink in the WordPress admin to your desired structure e.g.: /blog/%postname% 2) Add the "slug" and "with_front" parameter to the rewrite-array in the register_post_type function. "slug" must be the name of your post-type. $args = array( // ... 'rewrite' => array( ...


6

I think the add_rewrite_tag() is not needed, and can be replaced with adding the variables to the public query vars directly: // Either directly (in your init hook): $wp->add_query_var( 'var1' ); $wp->add_query_var( 'var2' ); // Or via a filter: add_filter( 'query_vars', 'wpse12965_query_vars' ); function wpse12965_query_vars( $query_vars ) { ...


6

You can do the following: /* add new rewrite rule */ function attachment_rewrite( $wp_rewrite ) { $rule = array( 'media/(.+)' => 'index.php?attachment=' . $wp_rewrite->preg_index(1) ); $wp_rewrite->rules = $rule + $wp_rewrite->rules; } add_filter( 'generate_rewrite_rules', 'attachment_rewrite' ); /* redirect standard ...


6

As far as i know there is no way to force the url to uppercase. As for forcing the www. this can vary as to where you are hosting etc. Here is one generic way of doing this using your .htaccess file. # Forcing www. infront of domain RewriteEngine On Options +FollowSymLinks RewriteCond %{HTTP_HOST} ^(domain\.com)$ [NC] RewriteRule ^(.*)$ http://www.%1/$1 ...


6

Use the Vice Versa plugin to change the post type. Redirect the URL per .htaccess: Redirect permanent /old-url /new-url


6

I figured it's about time i at least tried my hand at wiping out attachment pages. Here's my first shot at it... add_filter( 'attachment_fields_to_edit', 'wpse_25144_attachment_fields_to_edit', 10000, 2 ); function wpse_25144_attachment_fields_to_edit( $form_fields, $post ) { $url_type = get_option( 'image_default_link_type' ); if( 'post' == ...


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 ...


6

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, ...


6

$_SERVER['REQUEST_URI'] will not be empty in WordPress, because it is filled in wp_fix_server_vars() (file wp-includes/load.php). This function is called in wp-settings.php before any plugin is loaded. So you can use it. But always escape the value. It is global and can be changed by any other code, so you cannot trust its value.


5

Hook into wp_insert_post, test the post status for auto-draft, and the URL for a GET parameter. But first we need a helper function to get and sanitize the GET parameter: /** * Set default category. * * @wp-hook pre_option_default_category * @return string Category slug */ function t5_get_default_cat_by_url() { if ( ! isset( $_GET['post_cat'] ) ) ...


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

You can use the filter get_avatar for get all data to the avatar, also the url inside the markup. I think, WP don`t have an function for return only the url if the avatar image. $avatar = "<img alt='{$safe_alt}' src='{$default}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />"; apply_filters('get_avatar', ...


5

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 ...


5

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[ ...


5

Have a read of the following thread on the WordPress forum, apparently the AddThis plugin is the reason the hash tag is been appended to the URL. http://wordpress.org/support/topic/random-hashtag-strings-added-to-url-in-firefox


5

I would highly recommend that you NOT move wp-content outside of the docroot. WordPress utilizes wp-content for more than uploads. This would have a huge impact on the accessibility of themes and plugins. WordPress uploader will not play well with this scenario, and you're only allowed to add an alternate relative relative path to the WordPress URI as well ...


5

I guess this'll solve your query... WordPress Reserved Terms. Just search for 'name', it's there.


5

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 ...



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