Created
March 22, 2024 11:25
-
-
Save geomarts/ce42529e4ad593b59278e4cc49fc83d6 to your computer and use it in GitHub Desktop.
Useful Functions for Accessing Core WordPress/WooCommerce Pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* WordPress - Static Front Page | |
*/ | |
// GET ID | |
$front_page_id = get_option( 'page_on_front' ); | |
// GET URL | |
function get_front_page_url() { | |
return get_permalink( get_option( 'page_on_front' ) ); | |
} | |
// GET TITLE | |
function get_front_page_title() { | |
return get_the_title( get_option( 'page_on_front' ) ); | |
} | |
/* | |
<a href="<?php echo esc_url( get_front_page_url() ); ?>"> | |
<?php echo esc_html( get_front_page_title() ); ?> | |
</a> | |
*/ | |
/** | |
* WordPress - Static Blog Page | |
*/ | |
// GET ID | |
$blog_page_id = get_option( 'page_for_posts' ); | |
// GET URL | |
// Method 1 | |
function get_blog_page_url() { | |
return get_permalink( get_option( 'page_for_posts' ) ); | |
} | |
// Method 2 | |
function get_blog_page_url2( $type ) { | |
return get_post_type_archive_link( $type ); | |
} | |
// GET TITLE | |
function get_blog_page_title() { | |
return get_the_title( get_option( 'page_for_posts' ) ); | |
} | |
/* | |
<a href="<?php echo esc_url( get_blog_page_url() ); ?>"> | |
<?php echo esc_html( get_blog_page_title() ); ?> | |
</a> | |
*/ | |
/* | |
<a href="<?php echo esc_url( get_blog_page_url2( 'post' ) ); ?>"> | |
<?php echo esc_html( get_blog_page_title() ); ?> | |
</a> | |
*/ | |
/** | |
* WooCommerce - My Account Page | |
*/ | |
// GET ID | |
$my_account_page_id = get_option( 'woocommerce_myaccount_page_id' ); | |
$my_account_page_id2 = wc_get_page_id( 'myaccount' ); | |
/* GET URL */ | |
// Method 1 | |
function get_my_account_page_url() { | |
return get_permalink( get_option( 'woocommerce_myaccount_page_id' ) ); | |
} | |
// Method 2 | |
function get_my_account_page_url2() { | |
return get_permalink( wc_get_page_id( 'myaccount' ) ); | |
} | |
// Method 3 | |
function get_my_account_page_url3() { | |
return wc_get_page_permalink( 'myaccount' ); | |
} | |
/* GET TITLE */ | |
// Method 1 | |
function get_my_account_page_title() { | |
return get_the_title( get_option( 'woocommerce_myaccount_page_id' ) ); | |
} | |
// Method 2 | |
function get_my_account_page_title2() { | |
return get_the_title( wc_get_page_id( 'myaccount' ) ); | |
} | |
/* | |
<a href="<?php echo esc_url( get_my_account_page_url() ); ?>"> | |
<?php echo esc_html( get_my_account_page_title() ); ?> | |
</a> | |
*/ | |
/** | |
* WooCommerce - Shop Page | |
*/ | |
// GET ID | |
$shop_page_id = get_option( 'woocommerce_shop_page_id' ); | |
$shop_page_id2 = wc_get_page_id( 'shop' ); | |
/* GET URL */ | |
// Method 1 | |
function get_shop_page_url() { | |
return get_permalink( get_option( 'woocommerce_shop_page_id' ) ); | |
} | |
// Method 2 | |
function get_shop_page_url2() { | |
return get_permalink( wc_get_page_id( 'shop' ) ); | |
} | |
// Method 3 | |
function get_shop_page_url3() { | |
return wc_get_page_permalink( 'shop' ); | |
} | |
/* GET TITLE */ | |
// Method 1 | |
function get_shop_page_title() { | |
return get_the_title( get_option( 'woocommerce_shop_page_id' ) ); | |
} | |
// Method 2 | |
function get_shop_page_title2() { | |
return get_the_title( wc_get_page_id( 'shop' ) ); | |
} | |
/* | |
<a href="<?php echo esc_url( get_shop_page_url() ); ?>"> | |
<?php echo esc_html( get_shop_page_title() ); ?> | |
</a> | |
*/ | |
/** | |
* WooCommerce - Cart Page | |
*/ | |
// GET ID | |
$cart_page_id = get_option( 'woocommerce_cart_page_id' ); | |
$cart_page_id2 = wc_get_page_id( 'cart' ); | |
/* GET URL */ | |
// Method 1 | |
function get_cart_page_url() { | |
return get_permalink( get_option( 'woocommerce_cart_page_id' ) ); | |
} | |
// Method 2 | |
function get_cart_page_url2() { | |
return get_permalink( wc_get_page_id( 'cart' ) ); | |
} | |
// Method 3 | |
function get_cart_page_url3() { | |
return wc_get_page_permalink( 'cart' ); | |
} | |
// Method 4 | |
function get_cart_page_url4() { | |
return wc_get_cart_url(); | |
} | |
/* GET TITLE */ | |
// Method 1 | |
function get_cart_page_title() { | |
return get_the_title( get_option( 'woocommerce_cart_page_id' ) ); | |
} | |
// Method 2 | |
function get_cart_page_title2() { | |
return get_the_title( wc_get_page_id( 'cart' ) ); | |
} | |
/* | |
<a href="<?php echo esc_url( get_cart_page_url() ); ?>"> | |
<?php echo esc_html( get_cart_page_title() ); ?> | |
</a> | |
*/ | |
/** | |
* WooCommerce - Checkout Page | |
*/ | |
// GET ID | |
$checkout_page_id = get_option( 'woocommerce_checkout_page_id' ); | |
$checkout_page_id2 = wc_get_page_id( 'checkout' ); | |
/* GET URL */ | |
// Method 1 | |
function get_checkout_page_url() { | |
return get_permalink( get_option( 'woocommerce_checkout_page_id' ) ); | |
} | |
// Method 2 | |
function get_checkout_page_url2() { | |
return get_permalink( wc_get_page_id( 'checkout' ) ); | |
} | |
// Method 3 | |
function get_checkout_page_url3() { | |
return wc_get_page_permalink( 'checkout' ); | |
} | |
// Method 4 | |
function get_checkout_page_url4() { | |
return wc_get_checkout_url(); | |
} | |
/* GET TITLE */ | |
// Method 1 | |
function get_checkout_page_title() { | |
return get_the_title( get_option( 'woocommerce_checkout_page_id' ) ); | |
} | |
// Method 2 | |
function get_checkout_page_title2() { | |
return get_the_title( wc_get_page_id( 'checkout' ) ); | |
} | |
/* | |
<a href="<?php echo esc_url( get_checkout_page_url() ); ?>"> | |
<?php echo esc_html( get_checkout_page_title() ); ?> | |
</a> | |
*/ | |
/** | |
* Yith WooCommerce Wishlist - Wishlist Page | |
*/ | |
// GET ID | |
$yith_wishlist_page_id = get_option( 'yith_wcwl_wishlist_page_id' ); | |
$yith_wishlist_page_id2 = YITH_WCWL()->get_wishlist_page_id(); | |
/* GET URL */ | |
// Method 1 | |
function get_yith_wishlist_page_url() { | |
return get_permalink( get_option( 'yith_wcwl_wishlist_page_id' ) ); | |
} | |
// Method 2 | |
function get_yith_wishlist_page_url2() { | |
return YITH_WCWL()->get_wishlist_url(); | |
} | |
/* GET TITLE */ | |
function get_yith_wishlist_page_title() { | |
return get_the_title( get_option( 'yith_wcwl_wishlist_page_id' ) ); | |
} | |
/* | |
<a href="<?php echo esc_url( get_yith_wishlist_page_url() ); ?>"> | |
<?php echo esc_html( get_yith_wishlist_page_title() ); ?> | |
</a> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment