I generate css dynamically using query_vars.
Right now the url of query var is http://example.com/index.php?loadcss=mycss
How can I rewrite those urls into http://example.com/css/mycss.css instead of using query string that cannot cached, it would look better to use something like I wrote above.
I have read about add_rewrite_tag, but have no idea how to use it. Can someone give me direction how to use it?
In the case of wordpress I would just use a PHP to generate the dynamic CSS.
This is the method most people are using .
See HERE or HERE or HERE for example .
You have many ways to do this technique, some of them also show style.css and not style.php on the code (actually it is only about changing header or putting php code inside the css.. )
Could you not use a str_replace() since the url will be the same for each?
$baseURL = 'http://example.com/index.php?loadcss='
$cssURL = 'http://example.com/css/'
str_replace($baseURL . 'mycss', $cssURL . 'mycss.css', $the_queried_vars);
Try out the Redirection WordPress Plugin
Related
I checked this already and found a solution here (Q 34160546) which sadly does not work for me though, maybe anyone else has an idea?
I checked my site on pingdom and wanted to get rid of this problem they put up:
Resources with a “?” in the URL are not cached by some proxy caching servers. Remove the query string and encode the parameters into the URL for the following resources:
A bunch of jpgs are listed, but to keep it simple lets just look at my profile picture on the main homepage (right widget):
https://example.com/profile.jpg?w=192
This ? should be encoded with %3F and my question is how I can do that the best way? Within the widget code that generates the code above, I only included this:
<img src="https://example.com/profile.jpg" class="aligncenter" width="192">
Now I can’t just go ahead and write this instead, it will result in the picture not showing up:
<img src="https://example.com/profile.jpg%3Fw=192">
Can anyone tell me a quick fix for my ~25 images? Maybe it will improve the site speed..
In WordPress, this is possible to remove "?" from script and styles. But from the image, you need some customization.
you can use preg_replace, I did this little example for you.
<?php
$url = "http://www.test/img/FMR.jpg?Qq_0y12h";
echo "url = $url\n\n";
$urlFormatted = preg_replace("/\?.*$/", "", $url);
echo "urlFormatted = $urlFormatted\n";
?>
For more information,
Remove character from image url
PHP Remove parameters from image extension
Removing query string in PHP (sometimes based on referrer)
Or you may try this code also, not tested but this will help you. please visit
function remove_query_string($url) {
return remove_query_arg('w', $url);
}
add_filter('the_permalink', 'remove_query_string');
hope this will helps you.
Currently, I am using this page
http://irvinesprings.com/springs-manufacturer/
which has a shortcode which can read parameters passed using GET.
by adding
http://irvinesprings.com/springs-manufacturer/?spring=Tension&area=Irvine
It will read the get variable and generate some extra content and again it will change depending on the area.
Editing the rewrite rules aren't a problem as I've found a solution to adding the rules.
The existing rule for turning the page name into the correct rewrite rule
for /springs-manufacturer/
(.?.+?)(?:/([0-9]+))?/?$
which rewrites to
index.php?pagename=$matches[1]&page=$matches[2]
Ideally, I would like to have
/springs-manufacturer/spring/Tension/area/Irvine
which would have a rewritten URL of something like
/spring/(.*)/area/(.*) ?spring=$1&area=$2
I just can't for the life of me combine these two rules effectively to get this to work.
Regex Pattern
(springs-manufacturer)/spring/(.*)/area/(.*)$
Match
index.php?pagename=$matches[1]&spring=$matches[2]&area=$matches[3]
I'm currently developing a new site on Wordpress to replace an old Drupal site. The site is currently being developed on 'dev.website.com', and will be moved to 'website.com' once completed.
I'd like to use a relative image path like 'images/logo.png' instead of the absolute path as it'll make the switch a lot easier, as I won't have to manually remove 'dev.' before every single reference to a file path on the site.
Is there a plugin to do this, or a setting within the Wordpress admin itself? I've looked at loads of articles but they seem to be pretty complex for what I thought could be a simple fix.
Any help would be massively appreciated!
Here is simple solution for importing images
<img src="<?php bloginfo('template_directory');?>/images/image.jpg">
I always use <?php bloginfo('stylesheet_directoy'); ?>/images/image.jpg I create a lot of child themes and this works perfectly.
You can also define a constant with define(IMGPATH, STYLESHEETPATH . '/images'); and use something <?php IMGPATH . '/logo.png';
STYLESHEETPATH is a constant that WordPress uses.
I'm trying to apply a background-image to a header in a site.master file. If I use:
background-image:url('./themes/Modern/images/bg_full.png')
It works fine for all root level pages, but for any dynamic pages higher up directory structure it does not apply. So I changed it to:
background-image:url('~/themes/Modern/images/bg_full.png')
But when I do this the image does not show on any of the pages. Any help appreciated.
CSS is client based. Basically what your code does is creating a GET request like: http://domain.com/css/~/themes/Modern/images/bg_full.png
You probably want something like:
background-image:url('/themes/Modern/images/bg_full.png'); since this will result in a request like http://domain.com/themes/Modern/images/bg_full.png
background-image:url('http://your-domain-host.com/path_to_images/bg_full.png');
try it if not working then give me your page url i will give you exact code
I am trying to remove the default lightbox.js file coming from the Lightbox2 module, by using template.php, and load in my own. I would like to do this via template.php if possible, and not place this code in a custom module. I am adding my javascript file, then unsetting the module javascript file. The problem is $vars['scripts'] isn't getting replaced with the output from $js, and still outputting the module javascript. krumo($js) shows the default lightbox.js removed. Below is what I have in template_preprocess_page. Thanks in advance.
drupal_add_js(path_to_theme() . "/resources/js/lightbox.js", 'theme');
$js = drupal_add_js(NULL, NULL, 'header'); //get header js files in an array
$lightbox_path = drupal_get_path('module', 'lightbox2');
unset($js['module'][$lightbox_path . '/js/lightbox.js']); //unset lightbox default js
$vars['scripts'] = drupal_get_js('header', $js);
Alright, let's take another look at it, then.
Having just looked at http://api.drupal.org/api/function/drupal_add_js/6 a second time, I note that the lightbox code is probably in
$js['header']['module'][$lightbox_path .'/js/lightbox.js']
and not in
$js['module'][$lightbox_path .'/js/lightbox.js'].
I suggest sneaking a dpm($js) in before your 'unset' call, and then hit refresh a couple of times until it shows up, and make sure you've got the exact correct combination of $scope and $type to find the lightbox code at.
(Note: dpm() is a function provided by the devel module, which I guess I'm assuming your'e already using. If you're not, then drupal_set_message('<pre>'. print_r($js, TRUE) .'</pre>); will do as well.