Last active
August 29, 2015 13:58
-
-
Save j-mccarthy/9945291 to your computer and use it in GitHub Desktop.
Wordpress Functions Snippets
This file contains hidden or 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 | |
// re-order child style | |
function src_reorder_child_style() { | |
wp_dequeue_style( 'responsive-style-css' ); | |
wp_deregister_style( 'responsive-style-css'); | |
wp_enqueue_style( 'child-style', get_stylesheet_uri() ); | |
} | |
add_action( 'wp_enqueue_scripts', 'src_reorder_child_style', 20 ); | |
// Get excerpt by id function | |
function src_get_the_excerpt($post_id) { | |
global $post; | |
$save_post = $post; | |
$post = get_post($post_id); | |
$output = get_the_excerpt(); | |
$post = $save_post; | |
return $output; | |
} | |
<?php | |
// The right way to register sidebars from Just Tadlock | |
add_action( 'widgets_init', 'my_register_sidebars' ); | |
function my_register_sidebars() { | |
/* Register the 'primary' sidebar. */ | |
register_sidebar( | |
array( | |
'id' => 'primary', | |
'name' => __( 'Primary' ), | |
'description' => __( 'A short description of the sidebar.' ), | |
'before_widget' => '<div id="%1$s" class="widget %2$s">', | |
'after_widget' => '</div>', | |
'before_title' => '<h3 class="widget-title">', | |
'after_title' => '</h3>' | |
) | |
); | |
/* Repeat register_sidebar() code for additional sidebars. */ | |
} | |
// Remove editor from pages | |
function remove_editor() { | |
remove_post_type_support('page', 'editor'); | |
} | |
add_action('admin_init', 'remove_editor'); | |
/** | |
* Hide editor on specific pages. | |
* | |
*/ | |
add_action( 'admin_init', 'hide_editor' ); | |
function hide_editor() { | |
// Get the Post ID. | |
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ; | |
if( !isset( $post_id ) ) return; | |
// Hide the editor on the page titled 'Homepage' | |
$homepgname = get_the_title($post_id); | |
if($homepgname == 'Homepage'){ | |
remove_post_type_support('page', 'editor'); | |
} | |
// Hide the editor on a page with a specific page template | |
// Get the name of the Page Template file. | |
$template_file = get_post_meta($post_id, '_wp_page_template', true); | |
if($template_file == 'my-page-template.php'){ // the filename of the page template | |
remove_post_type_support('page', 'editor'); | |
} | |
} | |
// Change outgoing mail from sending as Wordpress to camplight email | |
function src_from_email() { | |
return "[email protected]"; | |
} | |
add_filter( 'wp_mail_from', 'src_from_email' ); | |
function src_from_name() { | |
return "Kieran"; | |
} | |
add_filter( 'wp_mail_from_name', 'src_from_name' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment