Wordpress Cheat Sheet - Blog - General Coding Tips for Web Design

GJC Website Design UK, Joomla Developer, VirtueMart Developer, Template Developer, web site designs, England, Britain, UK, Belgium, search-engine optimisation (SEO). Multilingual.

Home Blog Wordpress Cheat Sheet

Thu

14

Nov

Wordpress Cheat Sheet
  • Wordpress
  • Cheat Sheet


Wordpress Cheat Sheet

Here's a list of Wordpress code snippets so that I don't have to search the forums every time I need one!


Permalink

<?php the_permalink(); ?>
.......................................................

Is front page

is_front_page()
.......................................................

Get home page url

get_home_url()
.......................................................

Get the current post ID

get_the_ID()
.......................................................

Get the current category ID

$category = get_the_category();
$catid = $category[0]->cat_ID;
.......................................................

Get the current title and print

the_title()
.......................................................

Get the current title as string

get_the_title()
.......................................................

route to template folder in files

<?php bloginfo( 'template_directory' ); ?>
.......................................................

static home page

Settings->Reading->Front page displays
must be 2 different pages .. blog can be dummy blank page
.......................................................

shortcode in template files

<?php echo do_shortcode("[slider id='42' name='Boswell' size='full']") ?>

must be 2 different pages .. blog can be dummy blank page
.......................................................

Wordpress Woocommerce

Permalinks

Shop
<?php get_permalink( woocommerce_get_page_id( 'shop' ) ) ?>
.......................................................

Category
<?php get_term_link( 21 ,'product_cat') ?>
.......................................................

Product - is just a post
<?php get_permalink( '1087' ) ?>
.......................................................

My Account
<?php $myaccount_page_id = get_option( 'woocommerce_myaccount_page_id' ); if ( $myaccount_page_id ) {
$myaccount_page_url = get_permalink( $myaccount_page_id );
} ?>
.......................................................

Cart
<?php global $woocommerce;
$cart_url = $woocommerce->cart->get_cart_url(); ?>
.......................................................

Payment Page - typically /checkout/pay/
<?php $payment_page = get_permalink( woocommerce_get_page_id( 'pay' ) );
// make ssl if needed
if ( get_option( 'woocommerce_force_ssl_checkout' ) == 'yes' )
$payment_page = str_replace( 'http:', 'https:', $payment_page ); ?>
.......................................................

Logout
<?php $myaccount_page_id = get_option( 'woocommerce_myaccount_page_id' );
if ( $myaccount_page_id ) {
$logout_url = wp_logout_url( get_permalink( $myaccount_page_id ) );
if ( get_option( 'woocommerce_force_ssl_checkout' ) == 'yes' )
$logout_url = str_replace( 'http:', 'https:', $logout_url );
} ?>
.......................................................

Last Updated on Thursday, 09 November 2017 14:44
 



Wordpress Cheat Sheet|Blog | General Coding Tips for Web Design



GJC Website Design UK, Joomla Developer, VirtueMart Developer, Template Developer, web site designs, England, Britain, UK, Belgium, search-engine optimisation (SEO). Multilingual.


page, category, wordpress, current, title, cart, home, url, template, post, blank, cheat, sheet, dummy, different, files, pages, blog, shortcode, permalinks, typically, payment, shop, product, displays, checkout, account, logout, pay, woocommerce, string, search, forums, don, snippets, list, code, time, permalink, folder


guru

We use cookies to improve our website and your experience when using it. Cookies used for the essential operation of the site have already been set.
To find out more about the cookies we use and how to delete them, see our privacy policy.

I accept cookies from this site.