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


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


10

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


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.


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


8

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


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

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

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

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

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

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


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

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


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


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

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

Yes it's also possible for the password, by running a filter on lostpassword_url, which is basically the password equivalent of the login url.. Example Basically the same as before, just changed the function and hook names. add_filter( 'lostpassword_url', 'custom_lostpass_url' ); function custom_lostpass_url( $lostpassword_url ) { return ...


5

From the Codex entry for Data Validation: URLs: esc_url( $url, (array) $protocols = null ) (since 2.8) Always use esc_url when sanitizing URLs (in text nodes, attribute nodes or anywhere else). Rejects URLs that do not have one of the provided whitelisted protocols (defaulting to http, https, ftp, ftps, mailto, news, irc, gopher, nntp, ...


5

In order to do partition your blogs like this you're going to need to write a custom plugin similar to the WordPress MU Domain Mapping plugin. Here's how your plugin needs to work. Create a sunrise.php file for your plugin, and properly define('SUNRISE',true); in your wp-config.php file. Create a table which maps the tuples {blog_slug, blog_id, ...


5

In WordPress, "---" and " -- " become em-dashes (— &#8212;) and "--" becomes an en-dash (— #8212;). The sanitize_title_with_dashes() function doesn't catch these. That function uses the databased copy, but the title displayed to the user always goes through a texturize function. So if we replace en/em dashes on their way into the database, ...


5

I am trying to add in a script and css file for my plugin into the admin header. Then like any good developer you should be using wp_enqueue_script or wp_enqueue_style so you're not hard-coding those script/style includes into the plugin(meaning a user can unhook them if he/she needed to). http://codex.wordpress.org/Function_Reference/wp_enqueue_script ...


5

$my_url = 'my/relative/url.php'; echo site_url($my_url); site_url() when used by itself will return the absolute path to your blog. But, if you add an argument to it, as per my example above, it will prepend the absolute path to your path. Just make sure your URL doesn't contain a leading slash (eg: /this/may/not/work). Finally, if you happen to have your ...


5

If you want WP installed in a directory but the site home on your domain root, you need to move the main index.php file out to your domain root and edit the require statement to point within your directory. This process is outlined here: Giving WordPress Its Own Directory.



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