Changing attachment urls?

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 wordpress attachments urls to new format */ function redirect_old_attachment() { global $wp; if( !preg_match( ‘/^media\/(.*)/’, $wp->request ) … Read more

Preserve custom URL parameter on more pages

You will need to intercept the links generated by WordPress and append the query var onto the relevant URLs. You can do this quite easily with a filter on category URLs with something like… function add_my_query_var( $link ) { $link = add_query_arg( ‘sort’, ‘most_voted’, $link ); return $link; } add_filter(‘category_link’,’add_my_query_var’); I also spotted this handy … Read more

Is it safe to use $_SERVER[‘REQUEST_URI’]?

$_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. A different … Read more

How to use relative links on my pages?

$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 … Read more

How to reference a theme image in a stylesheet?

It depends on your image and stylesheet location. But this is the syntax: .theme-image { background-image: url(‘../images/header-img.jpg’); } The above code is for the structure wp-content – themes – your-theme – images – header-img.jpg – css – style.css You are making the browser come one directory before and search for images directory.

Change the author slug from nickname to ID

Surprised to see this unanswered for this long. This is pretty simple to do with a simple block of code: function set_my_nice_name() { global $wpdb; $user_table = $wpdb->prefix . ‘users’; $wpdb->query(“UPDATE $user_table SET `user_nicename`=`ID`”); } add_action(‘init’, ‘set_my_nice_name’); This works because the visible portion of an author slug (or profile slug in BuddyPress) uses the user_nicename … Read more

Multiple endpoints to same page

Okay… here’s how you add the rule. <?php add_action(‘init’, ‘add_my_rule’); function add_my_rule() { add_rewrite_rule(‘^test\/link.*$’,’index.php?pagename=about’,’top’); } ?> This rule will ensure that when you visit a url like http://…/test/link or http://…/test/link<xyz>, you are redirected to the about page (please make sure the slug for about page is ‘about’). Also, http://…/test/, will take you the test page … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)