Skip to content

Instantly share code, notes, and snippets.

@joshmcrty
joshmcrty / getfieldproperties.js
Created December 8, 2014 21:46
Get a SharePoint Site Column's Properties via REST
( function( $ ) {
$.ajax({
url: "http://<site-url>/_api/web/fields/getbytitle('Display Name of Field')",
type: "GET",
headers: { "accept": "application/json; odata=verbose" },
success: successHandler,
error: errorHandler
});
function successHandler( data ) {
/**
* navigation.js
*
* Handles toggling the navigation menu for small screens and enabling tab support for dropdown menus.
*/
( function() {
var container, button, menu, links;
container = document.getElementById( 'site-navigation' );
if ( ! container )
@joshmcrty
joshmcrty / SharePoint 2007 Page Redirect JavaScript
Created December 11, 2013 22:53
Drop this inside a <script> tag in a Content Editor Web Part to redirect a page to another URL without creating an entry in the browser history. Based on a blog post I wrote at http://joshmccarty.com/2011/08/redirect-in-sharepoint-using-meta-vs-javascript/ and @PathToSharePoint's easy tabs script to detect whether a page is in edit mode.
;( function() {
if ( document.forms[0].elements["_wikiPageMode.value"] == "true" || document.forms[0].elements["MSOLayout_InDesignMode"].value == "1") {
return;
}
window.location.replace('http://your-url-goes-here');
})();
@joshmcrty
joshmcrty / WordPress Apply Content Filter
Created July 18, 2013 18:44
Apply the WordPress content filters to a string of HTML from a custom field within the WordPress loop. The enables oEmbed, wp_texturize, etc.
<?php $my_custom_content = get_post_meta( $post->ID, 'my_custom_content_meta_key', true ); ?>
<?php if ( '' != $my_custom_content ) : ?>
<?php echo apply_filters( 'the_content', html_entity_decode( $my_custom_content ) ) ?>
<?php endif; ?>
@joshmcrty
joshmcrty / WordPress Default Title
Created September 8, 2012 21:15
Change the default text in the title field of a WordPress post (post, page, or custom post type)
function change_default_title( $title ) {
$screen = get_current_screen();
if ( 'post' == $screen->post_type ) { // Replace 'post' with the name of the post type you want to use with the new title
$title = 'Enter headline here';
}
return $title;
}
add_filter( 'enter_title_here', 'change_default_title' );