Tag Info

Hot answers tagged

15

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


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


13

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


12

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


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

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


10

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.


10

You can get the value of front in the global $wp_rewrite: global $wp_rewrite; echo $wp_rewrite->front; // or echo home_url( $wp_rewrite->front ); Though that is probably of limited use, as the front base isn't necessarily an existing page, and may 404 in many cases. If you're using that value to prepend to other URLs, you're likely doing it wrong. ...


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

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

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


7

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


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


7

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

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

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 can do that easily. You just need to specify a redirection parameter. If you are using a login link on the homepage to go to the login page, then @sisir's solution is correct. <?php echo wp_login_url( $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ); ?> If you are using a custom form on the frontpage, then inside the <form>, make sure you ...


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

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


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

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


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

$_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

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

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

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



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