Skip to content

Instantly share code, notes, and snippets.

View celticwebdesign's full-sized avatar

Darren Stevens celticwebdesign

View GitHub Profile
function my_page_template_redirect()
{
if ( is_category( 'uncategorized' ) ) {
$url = site_url( '/' );
wp_safe_redirect( $url, 301 );
exit();
}
}
add_action( 'template_redirect', 'my_page_template_redirect' );
@celticwebdesign
celticwebdesign / jQuery
Last active November 4, 2018 19:19
Select all links with hashes, MMenu mobile plugin, click menu button and scroll down on mobile.
// Select all links with hashes
$('.menu-item-1385 a, .menu-item-1386 a, .menu-item-1387 a, .menu-item-1383 a')
.click(
function(event) {
// On-page links
// console.log(this);
if (
location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '')
@celticwebdesign
celticwebdesign / Google Geocode
Created October 25, 2018 10:05
Geocoding a postcode using WordPress post meta.
$prev_location = get_post_meta($post->ID, '_cottages_custom_postal_code', true );
$lat = get_post_meta($post->ID, '_cottages_custom_location_latitude', true );
$lng = get_post_meta($post->ID, '_cottages_custom_location_longitude', true );
if (
(
$cottages_meta['_cottages_custom_postal_code'] != '' &&
$prev_location != $cottages_meta['_cottages_custom_postal_code']
) ||
@celticwebdesign
celticwebdesign / WordPress - non-sass css
Created May 28, 2018 20:15
Adding a non-sass css file to functions.php
function ascendia_scripts() {
wp_enqueue_style( 'ascendia-style', get_stylesheet_uri() );
wp_enqueue_style( 'ascendia-style-non-sass', get_template_directory_uri() . '/style-non-sass.css', array(), '20171001', 'all' );
}
add_action( 'wp_enqueue_scripts', 'ascendia_scripts' );
// https://codex.wordpress.org/Plugin_API/Action_Reference/admin_footer
function my_admin_add_js() {
echo '
<script type="text/javascript">
var ajaxurl = "'.admin_url("admin-ajax.php").'";
var user_id = '.get_current_user_id().';
</script>
// https://wordpress.stackexchange.com/questions/87261/checkboxes-in-registration-form
// REGISTRATION
add_action( 'register_form', 'signup_fields_wpse_87261' );
add_action( 'user_register', 'handle_signup_wpse_87261', 10, 2 );
// PROFILE
add_action( 'show_user_profile', 'user_field_wpse_87261' );
@celticwebdesign
celticwebdesign / Visual Composer - separate page
Created May 10, 2018 06:38
Allows display of Visual Composer on different page.
$post_id = get_field('above_footer');
$vcM = Vc_Manager::getInstance();
$vc = $vcM->vc();
$vc->addShortcodesCustomCss( $post_id );
$post = get_post($post_id, OBJECT);
$content = $post->post_content;
$content = apply_filters('wpautop', $content);
@celticwebdesign
celticwebdesign / PHP - select the last child with a specific class name in css
Created January 11, 2018 12:04
PHP - select the last child with a specific class name in css
// https://stackoverflow.com/questions/6401268/how-do-i-select-the-last-child-with-a-specific-class-name-in-css
if ( $( "section.recipe-collections" ).length > 1 ) {
$( "section.recipe-collections" ).last().addClass( "last" );
}
// Allows the selection of the last element with specific class.
@celticwebdesign
celticwebdesign / WordPress make category select with links
Created November 22, 2017 22:57
Gets a list of Category terms and make a linkable form select,