Skip to content

Instantly share code, notes, and snippets.

@kisabelle
kisabelle / wp-assign-parent-template.php
Created January 22, 2014 19:04
WordPress: Automatically Apply Parent Page Template to Child Pages by Matovu Richard
<?php
function switch_page_template() {
global $post;
// Checks if current post type is a page, rather than a post
if (is_page())
{
// Checks if page is parent, if yes, return
if ($post->post_parent == 0)
return true;
else if ($post->post_parent != $post->ID)
@kisabelle
kisabelle / bootstrap-rows.php
Created May 27, 2014 16:39
Wordpress + Bootstrap 3: Every two posts in their own row together.
<?php
// $the_query = new WP_Query( 'showposts=4' );
$the_query = new WP_query(
array(
'posts_per_page' => 4,
'meta_key' => 'featured_facts',
'orderby' => 'meta_value_num date',
'order' => DESC
)
);
@kisabelle
kisabelle / css-menu-icons.php
Created June 6, 2014 16:47
CSS Menu Icons / Wordpress Custom Menu Icons
function add_menu_icons_styles(){
?>
<style>
#adminmenu #menu-posts-mycustomposttype div.wp-menu-image:before {
content: "\f338";
}
</style>
<?php
@kisabelle
kisabelle / wp-pages-in-search.php
Created July 9, 2014 22:53
Add Pages to Wordpress Search Results
function my_custom_search_filter( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', array('post','page') );
}
return $query;
}
add_filter('pre_get_posts','my_custom_search_filter');
@kisabelle
kisabelle / acf-pagination.php
Last active December 30, 2024 16:05
ACF Repeater Field Pagination
<?php
/*
* Paginate Advanced Custom Field repeater
*/
if( get_query_var('page') ) {
$page = get_query_var( 'page' );
} else {
$page = 1;
}
@kisabelle
kisabelle / wp-change-display-name-existing-users.php
Created January 14, 2016 19:32
WordPress Change Default Display Name Publicy As First Name Last Name for all existing users
<?php
// Sets the user's display name (always) to first name last name, when it's avail.
add_action ('admin_head','make_display_name_f_name_last_name');
function make_display_name_f_name_last_name(){
$users = get_users(array('fields'=>'all'));
foreach($users as $user){
$user = get_userdata($user->ID);
# Restrict direct access to PHP files from theme or plugin directories
# Place in root .htaccess file
# Restrict direct access to PHP files from plugin directories
RewriteCond %{REQUEST_URI} !^/wp-content/plugins/file/to/exclude\.php
RewriteCond %{REQUEST_URI} !^/wp-content/plugins/directory/to/exclude/
RewriteRule wp-content/plugins/(.*\.php)$ - [R=404,L]
@kisabelle
kisabelle / disallow-file-edit.php
Created October 17, 2017 18:52
Disable File Editor in wp-config.php
define( 'DISALLOW_FILE_EDIT', true );
function custom_meta_box_markup()
{
// custom meta box markup goes here
}
function add_custom_meta_box()
{
add_meta_box("demo-meta-box", "Custom Meta Box", "custom_meta_box_markup", "post", "side", "high", null);
}
@kisabelle
kisabelle / acf-php-to-json.php
Created February 6, 2018 22:37
Convert ACF Fields Registered by PHP to Importable JSON Format
$groups = acf_get_local_field_groups();
$json = [];
foreach ($groups as $group) {
// Fetch the fields for the given group key
$fields = acf_get_local_fields($group['key']);
// Remove unecessary key value pair with key "ID"
unset($group['ID']);