Skip to content

Instantly share code, notes, and snippets.

<div class="navigation">
<ul>
<?php
$menu_name = 'main_nav';
if ( (
$locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) {
@mattjstrauss
mattjstrauss / gist:aeb7a4d08fb65995da61
Last active August 14, 2023 18:25 — forked from cameronbaney/gist:5006522
SQL to migrate WordPress site
UPDATE wp_options SET option_value = replace(option_value, 'Existing URL', 'New URL') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, 'Existing URL', 'New URL');
UPDATE wp_posts SET guid = REPLACE(guid, 'Existing URL', 'New URL') WHERE guid LIKE 'Existing URL/%';
UPDATE wp_postmeta SET meta_value = replace(meta_value,'Existing URL','New URL');
UPDATE wp_usermeta SET meta_value = replace(meta_value, 'Existing URL','New URL');
@mattjstrauss
mattjstrauss / ACF: Simple If Image Field
Last active February 16, 2016 15:30
ACF: Simple If Image Field
<?php
$image = get_field('image');
if( !empty($image) ):
// vars
$url = $image['url'];
$title = $image['title'];
@mattjstrauss
mattjstrauss / WP: Custom TinyMCE Style Plugin
Created August 6, 2015 13:24
WP: Custom TinyMCE Style Plugin
<?php
/*
Plugin Name: Custom Styles
Plugin URI: http://www.speckygeek.com
Description: Add custom styles in your posts and pages content using TinyMCE WYSIWYG editor. The plugin adds a Styles dropdown menu in the visual post editor.
Based on TinyMCE Kit plug-in for WordPress
http://plugins.svn.wordpress.org/tinymce-advanced/branches/tinymce-kit/tinymce-kit.php
*/
/**
* Apply styles to the visual editor
@mattjstrauss
mattjstrauss / WP: Simple WP Query
Created July 31, 2015 17:29
WP: Simple WP Query
<?php
$queryName = new WP_Query(
array(
'post_type'=>'POST_TYPE_NAME',
'posts_per_page'=>'-1',
'order'=>'ASC',
'orderby' => 'menu_order',
'post_status' => 'publish'
));
?>
@mattjstrauss
mattjstrauss / WP: Custom Menu Object
Last active August 29, 2015 14:26
This is using wp menu object and also incorporates adding classes and extra data to really customize the menu.
<?php
$menu_name = 'main_nav';
if ( (
$locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) {
$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
$menu_items = wp_get_nav_menu_items($menu->term_id);
@mattjstrauss
mattjstrauss / WP: Column Counter
Created June 22, 2015 17:28
Created columns by counting the amount of items then dividing it by how many columns you want
<?php
$totalColumns = count(get_sub_field('list_content')); // Total number of list items
$rowNumber = get_sub_field('list_columns'); // If you want to set the column number in the back end. If not set it to however many columns you want
$break = ceil($totalColumns / $rowNumber); // Rounded up number to add another column
$listCount = 0; // List count
?>
<?php if( have_rows('list_content') ): ?>
<ul class="column-<?php echo $rowNumber; ?>">
@mattjstrauss
mattjstrauss / WP: General Functions File
Last active March 16, 2019 23:01
Basic functions file for a general Wordpress Theme Setup
<?php
/**
* Custom Theme functions and definitions.
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package Custom_Theme
*/
/*--------------------------------------------------------------