Categories
PHP WordPress

Remove WordPress gallery shortcodes default styles

Add following snippet to your themes functions.php

Categories
PHP WordPress

Add dynamic version number to WordPress themes style.css

Prevent browsers using old cached styles by automatically adding file modification time as your themes style.css version number

Categories
JavaScript

Responsive iframe embeds

Make embedded iframes responsive
CSS:
JavaScript:

Categories
PHP WordPress

Remove extra 10 pixel space from WordPress caption

WordPress adds extra 10 pixels to captions with inline styles. To get rid of the unwanted space add following snippet to your themes functions.php

Categories
WordPress

Change site url with WP-CLI

$ wp search-replace 'site1.fi' 'site2.fi'
First parameter is the old URL and second parameter is the new URL

If you want to see the report without applying changes add --dry-run flag like in example below.
$ wp search-replace 'site1.fi' 'site2.fi' --dry-run

Changing site url in WordPress multisite

$ wp search-replace 'site1.fi' 'site2.fi'  --url='site1'

Read more about wp search-replace

Categories
PHP WordPress

Get page link from title in WordPress

Categories
PHP WordPress

Dequeue WMPL language-selector.css

WPML does not use wp_enqueue_style, but there is constant for language selector to prevent loading of the styles. Add following snippet to your functions.php.

Read more about WPML constants and functions

Categories
WordPress

Redirect to another page after Contact Form 7 submission

Add following line to your forms “Additional Settings”.
on_sent_ok: "location = 'http://example.com/thankyou';"

Categories
PHP WordPress

Add category support to WordPress pages

Category support for pages can be added with register_taxonomy_for_object_type() function. Add following example to your functions.php.

Categories
PHP WordPress

Display caption with post thumbnail in WordPress

 

<figure>
    <?php 
    the_post_thumbnail();
    $caption = get_post( get_post_thumbnail_id() )->post_excerpt;

    if ( $caption != "" ): ?>
        <figcaption>
            <?php echo $caption; ?>
        </figcaption>
    <?php endif; ?>
</figure>