Skip to content

Instantly share code, notes, and snippets.

View laurelstreng's full-sized avatar

Laurel laurelstreng

View GitHub Profile
@laurelstreng
laurelstreng / .htaccess
Created November 1, 2014 23:19
Password protect your website using the .htaccess file
AuthName "Restricted Area"
AuthType Basic
AuthUserFile /full/path/name/.htpasswd
require valid-user
@laurelstreng
laurelstreng / page.tpl.php
Created September 22, 2016 14:03
Drupal 7 - Print Views Block Content In Templates
<?php
$block = module_invoke('views', 'block_view', 'my_viewname-block');
print render($block);
?>
@laurelstreng
laurelstreng / theme-settings.php
Created September 22, 2016 14:14
Drupal 7 - Theme Settings Fieldset (group) of Fields
function THEMENAME_form_system_theme_settings_alter(&$form, $form_state, $form_id = NULL){
// Set up the a fieldset (group) for general information
$form['general_info'] = array(
'#type' => 'fieldset',
'#title' => t('General Information'),
'#description' => t('General contact information for Duke Health & Fitness Center.'),
);
$form['general_info']['address'] = array(
'#type' => 'textfield',
'#title' => t('Address'),
@laurelstreng
laurelstreng / page.tpl.php
Last active September 22, 2016 14:43
Drupal 7 - Theme Settings Image Field
<?php if (theme_get_setting('new_logo')): ?>
<div class="new-logo">
<?php
$fid = theme_get_setting('new_logo');
$image_url = file_create_url(file_load($fid)->uri);
?>
<img src="<?php echo $image_url; ?>"/>
</div>
<?php endif; ?>
@laurelstreng
laurelstreng / page.tpl.php
Last active September 22, 2016 14:42
Drupal 7 - Theme Settings WYSIWYG Field
<?php if (theme_get_setting('features_title')): ?>
<div class="features-title">
<?php $featurestitle = theme_get_setting('features_title'); ?>
<?php print check_markup($featurestitle['value'], $featurestitle['format']); ?>
</div>
<?php endif; ?>
@laurelstreng
laurelstreng / woocommerce-functions.php
Created November 2, 2017 12:43
Woocommerce changing "Default Sorting" to "Recommended sorting" on shop and product settings pages sorting dropdown
/**
* Woocommerce Sorting Dropdown
* @param $catalog_orderby
* @return mixed
*
* Changing "Default Sorting" to "Recommended sorting" on shop and product settings pages
*/
function ls_update_sorting_name( $catalog_orderby ) {
$catalog_orderby = str_replace("Default sorting", "Recommended sorting", $catalog_orderby);
return $catalog_orderby;
@laurelstreng
laurelstreng / woocommerce-functions.php
Created November 2, 2017 12:47
Woocommerce remove items from sorting dropdown
/**
* Woocommerce Sorting Dropdown
* @param $orderby
* @return mixed
*
* Remove items from sorting dropdown
*/
function ls_woocommerce_catalog_orderby( $orderby ) {
// We still need to add the functionality that actually does the sorting
$orderby['oldest_to_recent'] = __( 'Sort by date: oldest to newest', 'woocommerce' );
@laurelstreng
laurelstreng / MODULE_user.module
Created May 3, 2019 16:26
Drupal 8 Address Field – Reorder subfields in an Address field
// Form alter for the User Registration form
function MODULE_user_form_user_register_form_alter(&$form) {
if (isset($form['field_address'])) {
$form['field_address']['widget'][0]['address']['#after_build'][] = 'wrf_user_address_after_build';
}
}
// Custom function for #after_build
function MODULE_user_address_after_build($element, FormStateInterface $form_state) {
// Move the country field to the bottom
@laurelstreng
laurelstreng / .htaccess
Created May 14, 2019 12:40
Retrieve images from Production if not found locally
# Retrieve images from Production if not found locally
RewriteCond %{REQUEST_URI} ^/path/to/files/[^\/]*/?.*$
RewriteCond %{HTTP_HOST} !^www\.your-domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ https://www.your-domain.com/$1 [QSA,L]
@laurelstreng
laurelstreng / wordpress-query--postID-metaValue.php
Last active May 13, 2020 15:11
How to get Post ID by Meta Value
<?php
// Example: Query to show pages that have a meta_value that contains a string (not exact)
// https://rudrastyh.com/wordpress/meta_query.html
$args = array(
'post_type' => 'page',
'meta_query' => array(
array(
'value' => '[contact-form-7 id="13127" title="Alliance',
'compare' => 'LIKE'
)