Target certain pages using WordPress
Use this code to stop the title of the page such as ‘Home’ from being displayed as the H1 on the homepage. <?php if (!is_page(‘Home’)) { ?> <h1><?php the_title(); ?></h1> <?php } ?>
WordPress if page exists code
Use this to target code if a certain page exists, useful to show gallery images in a sidebar if there is a gallery page. <?php if(get_page_by_title(‘Gallery’)) : {code here} endif; ?>
Add Google Map to WordPress Site
Add the following to the functions.php file <?php function fn_googleMaps($atts, $content = null) { extract(shortcode_atts(array( "width" => ‘640’, "height" => ‘480’, "src" => ” ), $atts)); return ”; }…
Add breadcrumbs to WordPress without a plugin
Add this to your functions.php file function the_breadcrumb() { echo ‘<ul id="crumbs">’; if (!is_home()) { echo ‘<li><a href="’; echo get_option(‘home’); echo ‘">’; echo ‘Home’; echo "</a></li>"; if…
Move WordPress site to another domain name
Use these SQL commands if you are moving your website from one domain to another. Change Siteurl and Homeurl UPDATE wp_options SET option_value = replace(option_value, ‘http://www.nick-shaw.com’, ‘https://www.nick-shaw.co.uk’) WHERE option_name = ‘home’ OR option_name…
WordPress Display last post and image from specific category
Used to display the last post and image from a specific category, this can be useful for latest news on a homepage or latest posts in a sidebar. <?php query_posts(‘cat=3&showposts=1’); // replace 123 by category ID of "Headline" …
Re-direct all domains to one domain, regardless of subdomain
.htaccess rule to re-direct all domains to one domain, regardless of subdomain Options +FollowSymlinks RewriteEngine on rewritecond %{http_host} !^(.*)nick-shaw.co.uk [nc] rewriterule ^(.*)$ https://www.nick-shaw.co.uk/$1 [r=301,nc]
Recent Comments