Skip to content

Instantly share code, notes, and snippets.

View jayseventwo's full-sized avatar

jayseventwo jayseventwo

View GitHub Profile
@jayseventwo
jayseventwo / hide_deactivation_link.php
Created October 23, 2013 22:03
If you use a custom plugin to store all your theme functions, you dont want a user to deactivate it. Add this to functions.php or your custom theme plugin to hide the "deactivate" link for your selected plugin.
@jayseventwo
jayseventwo / hidethemes.php
Created October 23, 2013 21:53
Hide the WordPress theme menu from users other than the initial developer (user id is 1). Add to functions.php.
// hide themes menu in WordPress admin for users other than developer
add_action( 'admin_init', 'slt_lock_theme' );
function slt_lock_theme() {
global $submenu, $userdata;
get_currentuserinfo();
if ( $userdata->ID != 1 ) {
unset( $submenu['themes.php'][5] );
unset( $submenu['themes.php'][15] );
}
}
@jayseventwo
jayseventwo / svg_upload.php
Created October 13, 2013 23:20
Enable .svg format uploads in wordPress. Add to functions.php
// enable svg format file upload
add_filter('upload_mimes', 'custom_upload_mimes');
function custom_upload_mimes ( $existing_mimes=array() ) {
// add the file extension to the array
$existing_mimes['svg'] = 'mime/type';
@jayseventwo
jayseventwo / redirect.php
Created September 30, 2013 01:32
Redirect main navigation link to subpage. To do this, Add this code to functions.php, create your main navigation page using this template, then add your selected pages as the sub-pages. When you now click on the main nav button it should redirect to your child page (or first subpage if more than one).
<?php
/*
Template Name: Redirect To First Child
*/
if (have_posts()) {
while (have_posts()) {
the_post();
$pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");
$firstchild = $pagekids[0];
wp_redirect(get_permalink($firstchild->ID));
@jayseventwo
jayseventwo / global_custom_content
Created September 22, 2013 23:12
Add global custom content areas for your WordPress website. Add to functions.php
add_action('admin_menu', 'add_gcf_interface');
function add_gcf_interface() {
add_options_page('Opening hours', 'Opening hours', '8', 'functions', 'editglobalcustomfields');
}
function editglobalcustomfields() {
?>
<div class='wrap'>
<h2>Opening hours</h2>
/*
Make the Facebook Like box responsive (fluid width)
https://developers.facebook.com/docs/reference/plugins/like-box/
*/
/* This element holds injected scripts inside iframes that in some cases may stretch layouts. So, we're just hiding it. */
#fb-root {
display: none;
}
@jayseventwo
jayseventwo / Display date of all posts
Created July 23, 2013 05:12
In wordPress, when more than 1 post is added per day, the date only shows for the first post. This fixes that issue. Add to content.php
/* --- replace this --*/
<time datetime="<?php echo the_time('Y-m-j'); ?>" pubdate><?php the_date(); ?></time>
/* -- with this */
<time datetime="<?php echo the_time('Y-m-j'); ?>" pubdate><?php the_time(get_option('date_format')); ?></time>
@jayseventwo
jayseventwo / Ajaxify your WordPress comments
Last active July 5, 2021 16:43
Ajaxify your WordPress comments - no more submitting to a new page.
/* ------------------------------------------------------------------ajax comments - add to functions.php ------- */
add_action('comment_post', 'ajaxify_comments',20, 2);
function ajaxify_comments($comment_ID, $comment_status){
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
switch($comment_status){
case "0":
wp_notify_moderator($comment_ID);
case "1": //Approved comment
echo "success";
@jayseventwo
jayseventwo / Add pagination to WordPress
Created June 25, 2013 03:01
Add pagination to WordPress posts/pages - this example us using the Roots theme.
/*--- add to functions/custom.php */
/* ---------------------------------- custom pagination for posts -----*/
function j72_pagination($pages = '', $range = 2)
{
$showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
@jayseventwo
jayseventwo / sticky nav menu - twitter bootstrap
Created June 17, 2013 05:46
Create a sticky top nav menu using Twitter bootstrap - also works in WordPress themes based on Twitter Bootstrap
<!-- for fixed menu - surround nav menu -->
<div data-spy="affix" data-offset-top="200">
... header and nav menu ...
</div>
<!-- add to css -->
.affix {
top: 20px !important;