Snippets

36 posts

Show Link URL from HREF Attribute Using CSS

We can use CSS to display the URL of a link after the link. For this we don’t need to modify HTML as all work is done by CSS. This is the complete CSS to do this: a:after{ content: ‘ ‘ attr(href); // Style URL font-style:italic; color:blue; } The CSS […]

Add Pages, Custom Post Types in WordPress Site Feed

If you are running your WordPress site as a CMS, you may come across need to include pages from your site in the main feed, along with your posts. Well, the below code will give you that ability. function add_pages_to_rss_feed( $args ) { if ( isset( $args[‘feed’] ) && !isset( […]

Ultimate htaccess Redirects List

A list of useful htaccess redirects that you can easily implement on your site. Redirect removed pages Redirect deleted pages back to your site’s home page, or anywhere you want. RedirectMatch 301 /page1/?$ http://mydomain.com/ RedirectMatch 301 /page2/?$ http://mydomain.com/ If all pages share a common pattern, we can rewrite this in […]

Automatically Add Attributes to All Images in WordPress Posts

The below snippet will allow you to add an attribute to all images embedded in a WordPress post. function sumtips_image_attribute($content) { global $post; $pattern =”/<a(.*?)href=(‘|\”)(.*?).(bmp|gif|jpeg|jpg|png)(‘|\”)(.*?)>/i”; $replacement = ‘<a$1href=$2$3.$4$5 attribute=”attribute_value”‘; $content = preg_replace($pattern, $replacement, $content); return $content; } add_filter(‘the_content’, ‘sumtips_image_attribute’); Replace attribute=”attribute_value” to whatever attribute you need. Example: function sumtips_image_attribute($content) { […]

Exclude Certain Folders from htaccess Rewrite Rules

If you have an application or CMS running, you might have┬áSEO url’s enabled through .htaccess rewrites. Now installing a second application in a subfolder on the same domain can cause 404 errors. This is because all subfolders follow the rules specified in the root htaccess file. To prevent the errors, […]

Scaleable Full Screen Background Image with CSS3

With the background-size property in CSS3, we can get a full page scaleable background image. Here’s the CSS code: html { background: url(images/background.jpg) no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; } Background image is centered, automatically resized according to browser size, and retains the aspect […]