I was wondering if its possible to use the permalink settings in plugins instead of them using default non permalink urls.
For example i'm using the plugin flickr photostream which is downloadable from here http://wordpress.org/extend/plugins/flickr-photostream, its written by someone else, but I would like to know for my own plugins and to patch this one to create nicer permalinks instead of http://www.domain.co.uk/?flickrps=2
to go forward and back between pages.
Someone has suggested this url to me, and I have tried to attempt to patch this into the above plugin, but not having any luck to achieve what I am after.
Wordpress Plug-ins: How-to add custom URL Handles
I managed to find this via google, and seemed fairly easy to do, but am not getting the results I was expecting. http://gabrielharper.com/blog/2012/09/wordpress-custom-urls-for-plugins/
Instead of http://www.domain.co.uk/?flickrps=2
I would like the urls to be something similar to http://www.domain.co.uk/page/2
.
The links above that I would like to use sadly don't work and give error 404 on them, the links with the question marks in them however do work, but I would prefer not to use these.
I understand this is taken by WordPress but just after something like this, maybe photo would be better perhaps.
add_action('parse_request', 'addFlickrPhotostreamURL');
function addFlickrPhotostreamURL() {
global $flickrpsp;
// Manually parse the URL request
if (!empty($_SERVER['REQUEST_URI'])) {
$urlvars = explode('/', $_SERVER['REQUEST_URI']);
}
// Check for querystring variables
if ((!empty($urlvars[1])) && (!empty($urlvars[2]))) {
$_REQUEST['page'] = $urlvars[1];
$_REQUEST['flickrpsp'] = $urlvars[2];
$flickrpsp = $urlvars[2];
}
// ... handle multiple types of URL by checking $urlvars[1] here
}
You can view the code for the whole file here http://pastebin.com/cPhzrJBF.
You can easily achieve this by creating rules in .htaccess
file. For example to redirect URL http://www.domain.co.uk/?flickrps=2
to http://www.domain.co.uk/page/2
following rule can be used:
RewriteEngine on
RewriteRule ^page/([0-9]+)/$ ?flickrps=$1
Reference: htaccess url rewrite
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With