Skip to content

Instantly share code, notes, and snippets.

@brentini
brentini / csv_to_array.php
Created June 20, 2018 01:36 — forked from jaywilliams/csv_to_array.php
Convert a comma separated file into an associated array.
<?php
/**
* Convert a comma separated file into an associated array.
* The first row should contain the array keys.
*
* Example:
*
* @param string $filename Path to the CSV file
* @param string $delimiter The separator used in the file
* @return array
@brentini
brentini / Forcing SSL and WWW using .htaccess
Created May 29, 2018 20:24
Forcing SSL and WWW using .htaccess #htaccess #apache #ssl
RewriteEngine on
# Force www: from http://stackoverflow.com/a/4958847/1078583
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Force SSL: From http://stackoverflow.com/q/24322035/
RewriteCond %{HTTPS} off
@brentini
brentini / wordpress-hooks-metabox.php
Last active March 23, 2018 21:27 — forked from 5A5K1A/wordpress-hooks-metabox.php
WordPress Change 'Featured Image' metabox #wordpress
<?php
/* Featured Image Metabox : change the text in the current metaboxes
/* -------------------------------------------------- */
add_filter( 'admin_post_thumbnail_html', function( $content ) {
if(get_post_type() == 'post') {
$content = str_replace('Uitgelichte afbeelding', 'Nieuws foto', $content);
// $content .= '<p>Een extra uitlegtekst.</p>';
} elseif(get_post_type() == 'page') {
$content = str_replace('Uitgelichte afbeelding', 'Header foto', $content);
@brentini
brentini / wordpress-hooks-admin.php
Last active March 23, 2018 21:28 — forked from 5A5K1A/wordpress-hooks-admin.php
WordPress Remove Dashboard sections for "simple users" #wordpress
<?php
/* Hide certain admin sections for "simple users"
/* -------------------------------------------------- */
add_action('wp_dashboard_setup', function() {
if( current_user_can('editor') ) {
remove_meta_box('dashboard_quick_press', 'dashboard', 'side'); //Quick Press widget
remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side'); //Recent Drafts
remove_meta_box('dashboard_primary', 'dashboard', 'side'); //WordPress.com Blog
remove_meta_box('dashboard_secondary', 'dashboard', 'side'); //Other WordPress News
remove_meta_box('dashboard_incoming_links', 'dashboard', 'normal'); //Incoming Links
@brentini
brentini / function_css.php
Last active March 23, 2018 21:28 — forked from muzahedul03/function_css.php
How Include CSS file in Wordpress using Function #wordpress
<?php
//includes all felxo_theme_file_css
function flexo_theme_file(){
//inculde CSS file
wp_register_style('bootstrap', get_template_directory_uri(). '/css/bootstrap.min.css', array(), '3.1.0',all);
wp_register_style('fancybox', get_template_directory_uri(). '/css/fancybox/jquery.fancybox.css', array(), '3.1.0',all);
wp_register_style('jcarousel', get_template_directory_uri(). '/css/jcarousel.css', array(), '3.1.0',all);
@brentini
brentini / function_js.php
Last active March 23, 2018 21:28 — forked from muzahedul03/function_js.php
How to Use JS file in Wordpress using Function #wordpress
<?php
//includes all felxo_theme_file_css
function flexo_theme_file(){
//include jS file
wp_enqueue_script('jquery');
wp_enqueue_script('easing-js', get_template_directory_uri(). '/js/jquery.easing.1.3.js', array('jquery'), '1.3', true);
@brentini
brentini / functions.php
Last active March 23, 2018 21:29 — forked from ibndawood/functions.php
Wordpress - Google Maps API Key #wordpress
function ec_child_google_maps_api() { ?>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDRYczTDT6kSz-bWGrLGh6WCaBgUSL-1Dk" type="text/javascript"></script>
<?php }
add_action( 'wp_footer', 'ec_child_google_maps_api', 10 );
@brentini
brentini / title_lang_charset2.php
Last active March 23, 2018 21:29 — forked from muzahedul03/title_lang_charset2.php
How use language,title,Charset attributes in WordPress By PHP #wordpress
<html <?php language_attributes();?>>
<meta charset="<?php bloginfo('charset');?>">
<title><?php wp_title( '|', true, 'right' ); ?></title>
@brentini
brentini / wordpress.add.acf.content.to.search.results.php
Last active December 7, 2019 19:22 — forked from coffeepostal/wordpress.add.acf.content.to.search.results.php
WordPress: Add ACF Content to Search Results #wordpress
/*******************************
ADD ACF TO SEARCH RESULTS
*******************************/
/* Join posts and postmeta tables: http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_join */
function cf_search_join( $join ) {
global $wpdb;
if ( is_search() ) {
$join .=' LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
@brentini
brentini / get_dynamic_sidebar.php
Last active March 23, 2018 21:29 — forked from markhowellsmead/get_dynamic_sidebar.php
WordPress: get a dynamic sidebar as a string #wordpress
<?php
if (!function_exists('get_dynamic_sidebar')) {
function get_dynamic_sidebar($sidebar_id)
{
ob_start();
dynamic_sidebar($sidebar_id);
$out = ob_get_contents();
ob_end_clean();
return $out;