Skip to content

Instantly share code, notes, and snippets.

@brentini
brentini / shortcode-template.php
Last active March 23, 2018 21:42 — forked from andreawetzel/shortcode-template.php
WordPress Shortcodes for Template Parts #wordpress
/*
* Add shortcode support for template parts
* Example: [template_part path="template-part-leadership"]
*/
function template_part( $atts, $content = null ){
$tp_atts = shortcode_atts(array(
'path' => null,
), $atts);
ob_start();
@brentini
brentini / install.php
Last active March 23, 2018 21:43 — forked from Faisalawanisee/install.php
WordPress custom install script #wordpress
<?php
/**
* WordPress custom install script.
*
* Drop-ins are advanced plugins in the wp-content directory that replace WordPress functionality when present.
*
* Language: nl
*
* if ( file_exists( WP_CONTENT_DIR . '/install.php' ) ) {
* require ( WP_CONTENT_DIR . '/install.php' );
@brentini
brentini / emails.php
Last active March 23, 2018 21:27 — forked from tameemsafi/emails.php
Send an email programmatically in wordpress with wp_mail using the woocommerce transaction emails template. #wordpress
<?php
// Define a constant to use with html emails
define("HTML_EMAIL_HEADERS", array('Content-Type: text/html; charset=UTF-8'));
// @email - Email address of the reciever
// @subject - Subject of the email
// @heading - Heading to place inside of the woocommerce template
// @message - Body content (can be HTML)
function send_email_woocommerce_style($email, $subject, $heading, $message) {
@brentini
brentini / functions.php
Last active March 23, 2018 21:43
Add child theme scripts in wordpress child theme #wordpress
<?php
if ( ! function_exists( 'child_theme_scripts' ) ) {
add_action( 'wp_enqueue_scripts', 'child_theme_scripts' );
function child_theme_scripts() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( 'parent-style' ) );
}
}
@brentini
brentini / custom_user_fields.php
Last active March 23, 2018 21:43 — forked from dankerizer/custom_user_fields.php
add custom WordPress user fields #wordpress
<?php
/**
* ampinstant Project
* @package ampinstant
* User: dankerizer
* Date: 18/03/2017 / 03.36
*/
function wpinstant_extra_profile_fields( $user ) { ?>
@brentini
brentini / custom_post_types.php
Last active March 23, 2018 21:43 — forked from bronwynv/custom_post_types.php
This is set of helper classes to create and manage custom post types for WordPress. It gets added to a theme's logic folder, or libs or includes folders, and included in functions.php. Then the primary tracker class is initiated once, and used to create new CTPs. #wordpress
<?php
/***********************************************************************/
/*************************** TRACKER CLASS ***************************/
/***********************************************************************/
class Custom_Post_Types_Manager {
public $ctp_slugs;
public $prefix;
@brentini
brentini / wordpress-utils.php
Last active March 23, 2018 21:42 — forked from 5A5K1A/wordpress-utils.php
WordPress usefull utils / extra methods #wordpress
<?php
/**
* Strips url from obsolete stuff, for prettier display
* @param string $url The url
* @return string The cleaned up & pretty url for displaying
*/
function studio_strip_url( $url ) {
return rtrim( str_replace(array( 'https://', 'http://', 'mailto:', 'tel:', 'www.' ), '', $url), '/' );
}
@brentini
brentini / CF7InsertPost.php
Last active March 23, 2018 21:42 — forked from fernandoyada/CF7InsertPost.php
WordPress - Insert Post from Contact Form 7 #wordpress
<?php
/*
Plugin Name: CF7InsertPost
Version: 1
Author:
License: GPL3
*/
add_action('wpcf7_before_send_mail', 'cf7_insert_post', 10, 1);
function cf7_insert_post( $data ) {
@brentini
brentini / functions.php
Last active March 23, 2018 21:44 — forked from Neshable/functions.php
Adding Custom Post Type to WordPress #wordpress
// Register Custom Post Type
function books_post() {
// Array of custom labels for our custom post type backend.
$labels = array(
'name' => 'Books', //general name for the post type, usually plural. Default is Posts/Pages
'singular_name' => 'Book', //name for single object of this post type. Default is Post/Page
'menu_name' => 'Books', // Name used in the menu
'name_admin_bar' => 'Book', // String for use in New in Admin menu bar. - New Book
'add_new_item' => 'Add New Book', // Default is Add New Post/Add New Page.
@brentini
brentini / walker.php
Last active March 23, 2018 21:44 — forked from TwisterMc/walker.php
WordPress Walker Code #wordpress
<?php
/* I'm not so certain this works right anymore, but some may find it useful. See https://www.twistermc.com/36600/wordpress-mega-menu/ for full details. */
class description_walker extends Walker_Nav_Menu {
protected $topLevelId = NULL;
protected $topLevelCount = NULL;
protected $templateURL = NULL;
function description_walker() {
$this->templateURL = get_theme_root() . '/' . get_template() . '/';