Skip to content

Instantly share code, notes, and snippets.

View saxap's full-sized avatar
🙃

Sergey Astafev saxap

🙃
View GitHub Profile
add_action( 'template_redirect', 'so16179138_template_redirect', 0 );
function so16179138_template_redirect()
{
if( is_singular() )
{
global $post, $page;
$num_pages = substr_count( $post->post_content, '<!--nextpage-->' ) + 1;
if( $page > $num_pages ){
include( get_template_directory() . '/404.php' );
exit;
function set_max_height(elms, addh) {
if (typeof(addh) === 'undefined') addh = 0;
var maxHeight = Math.max.apply(null, elms.map(function (){
return jQuery(this).height();
}).get());
elms.height(maxHeight+addh);
}
@saxap
saxap / regenrate.php
Created October 16, 2016 10:46
Regenerate attachment on the fly wordpress
require_once( ABSPATH . 'wp-admin/includes/image.php' );
$img_id = get_post_thumbnail_id( $service->ID );
$parsed = parse_url( wp_get_attachment_url( $img_id ) );
$url = ABSPATH . dirname( $parsed [ 'path' ] ) . '/' . rawurlencode( basename( $parsed[ 'path' ] ) );
$url = str_replace('/', '/', $url);
$attach_data = wp_generate_attachment_metadata( $img_id, $url );
wp_update_attachment_metadata( $img_id, $attach_data );
@saxap
saxap / modx-snippets.php
Created February 1, 2017 08:53 — forked from christianhanvey/modx-snippets.php
Useful snippets for MODX Revo
Snippet: [[SnippetName]]
Chunk: [[$ChunkName]]
System Setting: [[++SettingName]]
TV: [[*fieldName/TvName]]
Link tag: [[~PageId? &paramName=`value`]]
Placeholder: [[+PlaceholderName]]
<?php