Skip to content

Instantly share code, notes, and snippets.

View dsebao's full-sized avatar
🏠
Working from home

Sebastian Ortiz dsebao

🏠
Working from home
View GitHub Profile
@dsebao
dsebao / functions.php
Last active December 18, 2015 09:39
Detect images attached to post - WordPress
<?php
//PASTE THIS IN FUNCTIONS
function my_image($postid=0, $size='thumbnail') { //it can be thumbnail or full
if ($postid<1){
$postid = get_the_ID();
}
if(has_post_thumbnail($postid)){
$imgpost = wp_get_attachment_image_src(get_post_thumbnail_id($postid), $size);
return $imgpost[0];
@dsebao
dsebao / functions.php
Created June 12, 2013 03:13
Simple visit counting in WordPress
<?php
//In function.php
function get_post_views($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0";
@dsebao
dsebao / myscript.js
Created June 25, 2013 00:42
Random images with jQuery (example for Wordpress theme)
$(document).ready(function(){
var images = ['image1.jpg', 'image2.jpg','image3.jpg'];
$('#bg').css({'background-image': 'url(wp-content/themes/mytheme/images/' + images[Math.floor(Math.random() * images.length)] + ')'});
});
@dsebao
dsebao / functions.php
Last active December 19, 2015 06:39
Agregar custom meta data al buscador de WordPress
<?php
function custom_search_query( $query ) {
$custom_fields = array(
//agregamos los valores de los custom meta data
"_post_title",
"custom_meta1",
"custom_meta2"
);
$searchterm = $query->query_vars['s'];
$query->query_vars['s'] = "";
@dsebao
dsebao / script.js
Created September 13, 2013 13:26
Input placeholder text fix for IE
$(document).ready(){
$('[placeholder]').focus(function() {
var input = $(this);
if(input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
if (input.val() == '' || input.val() == input.attr('placeholder')) {
@dsebao
dsebao / gistify496067.js
Last active December 23, 2015 04:58
Check if a plugin is loaded (Javascript)
if($().nombrePlugin) {
// if nombrePLugin is loaded and available
}
//OR
if($.fn.nombrePlugin !== undefined) {
// if nombrePLugin is loaded and available
}
@dsebao
dsebao / language-wp.php
Last active December 23, 2015 07:28
Language swtich in WP
<?php
function lang_support() {
return array('en','fr');
// Add your support lang-code (1st place is a default)
}
function rewrite_lang(){
$langs = lang_support();
foreach($langs as $lang) {
@dsebao
dsebao / function.php
Created October 1, 2013 21:48
WP Query reference
<?php
/**
* WordPress Query Comprehensive Reference
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query
* Source: http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/query.php
*/
$args = array(
//////Author Parameters - Show posts associated with certain author.
'author' => '1,2,3,', //(int) - use author id [use minus (-) to exclude authors by ID ex. 'author' => '-1,-2,-3,']
@dsebao
dsebao / functions.php
Created October 7, 2013 02:54
Wordpress SEO without plugins
<?php
function basic_wp_seo() {
global $page, $paged, $post;
$default_keywords = 'wordpress, plugins, themes, design, dev, development, security, htaccess, apache, php, sql, html, css, jquery, javascript, tutorials'; // customize
$output = '';
// description
$seo_desc = get_post_meta($post->ID, 'mm_seo_desc', true);
$description = get_bloginfo('description', 'display');
$pagedata = get_post($post->ID);
@dsebao
dsebao / click.js
Created October 9, 2013 16:34
Clickeable div
$(function(){
$('.thediv').click(function(){
window.location = $(this).find('a').attr('href');
});
})