Skip to content

Instantly share code, notes, and snippets.

@ivandoric
ivandoric / gist:11219318
Created April 23, 2014 15:12
php: str_ireplace multiple values
<?php
$find = array("vlaue1", "value2", "value3");
$replace = array("replacevalue1","replacevalue2","replacevalue3");
str_ireplace($find,$replace,$string);
?>
@ivandoric
ivandoric / gist:11219354
Created April 23, 2014 15:13
wordpress: Print the link of the featured image
<?php if ( has_post_thumbnail()) {
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full');
echo $large_image_url[0];
}
?>
@ivandoric
ivandoric / gist:11219384
Created April 23, 2014 15:14
wordpress: Add custom field to gallery popup Wordpress
<?php
/* For adding custom field to gallery popup */
function ime_autora_field($form_fields, $post) {
$form_fields["ime-autora"] = array(
"label" => __("Autor"),
"input" => "text",
"value" => get_post_meta($post->ID, "_ime-autora", true),
"helps" => __("Ime autora slike"),
@ivandoric
ivandoric / gist:11219463
Created April 23, 2014 15:15
wordpress: Multiple excerpt lenghts in wordpress
<?php
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
@ivandoric
ivandoric / gist:11219508
Created April 23, 2014 15:16
wordpress: is_tree function - Check if on certain page or on page children function
<?php
function is_tree($pid) {
global $post;
$anc = get_post_ancestors( $post->ID );
foreach($anc as $ancestor) {
if(is_page() && $ancestor == $pid) {
return true;
}
}
if(is_page()&&(is_page($pid)))
@ivandoric
ivandoric / gist:11220502
Created April 23, 2014 15:41
wordpress: Default editor styles
/* == WordPress WYSIWYG Editor Styles == */
.entry-content img {
margin: 0 0 1.5em 0;
}
.alignleft, img.alignleft {
margin-right: 1.5em;
display: inline;
float: left;
}
@ivandoric
ivandoric / gist:11220540
Created April 23, 2014 15:42
wordpress: Print featured image title insted of post title
/* Add this to functions.php */
<?php
function pj_featured_img_title() {
global $post;
$pj_thumbnail_id = get_post_thumbnail_id($post->ID);
$pj_thumbnail_image = get_posts(array('p' => $pj_thumbnail_id, 'post_type' => 'attachment', 'post_status' => 'any'));
if ($pj_thumbnail_image && isset($pj_thumbnail_image[0])) {
return $pj_thumbnail_image[0]->post_title;
}
@ivandoric
ivandoric / gist:11220615
Last active August 29, 2015 14:00
wordpress: Exclude certain categories
<?php /* Using this instead the_category */
function the_category_filter($thelist,$separator=' ') {
if(!defined('WP_ADMIN')) {
//list the category names to exclude
$exclude = array('Featured', 'Show');
$cats = explode($separator,$thelist);
$newlist = array();
foreach($cats as $cat) {
$catname = trim(strip_tags($cat));
if(!in_array($catname,$exclude))
@ivandoric
ivandoric / gist:11220757
Created April 23, 2014 15:47
wordpress: Remove styling for WP gallery
<?php
add_filter('gallery_style',
create_function(
'$css',
'return preg_replace("#<style type=\'text/css\'>(.*?)</style>#s", "", $css);'
)
);
@ivandoric
ivandoric / gist:11220813
Created April 23, 2014 15:49
drupal: Print custom menu links
/*Print custom menu links*/
<?php print theme('links', menu_navigation_links('menu-MENU-NAME'), array('id' => 'menu', 'class' => 'links')); ?>