Skip to content

Instantly share code, notes, and snippets.

@joshmcrty
joshmcrty / getfieldproperties.js
Created Dec 8, 2014
Get a SharePoint Site Column's Properties via REST
View getfieldproperties.js
( 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 ) {
View navigation.js
/**
* 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 Dec 11, 2013
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.
View SharePoint 2007 Page Redirect JavaScript
;( 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 Jul 18, 2013
Apply the WordPress content filters to a string of HTML from a custom field within the WordPress loop. The enables oEmbed, wp_texturize, etc.
View WordPress Apply Content Filter
<?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 Sep 8, 2012
Change the default text in the title field of a WordPress post (post, page, or custom post type)
View WordPress Default Title
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' );