Skip to content

Instantly share code, notes, and snippets.

View mafsdisseny's full-sized avatar

Miguel A. Fdez. mafsdisseny

View GitHub Profile
add_action( 'get_header', 'themeprefix_cpt_microdata' );
//Change microdata for events custom post type
function themeprefix_cpt_microdata() {
if ('event' == get_post_type()) {//change to your cpt
//add in the microdata changes
add_filter( 'genesis_attr_entry', 'themeprefix_genesis_attributes_entry', 20 );
@mafsdisseny
mafsdisseny / functions.php
Created April 22, 2015 13:18
Limit WordPress search to post titles, apply site-wide
<?php
// Buscar solo coincidencias en el titulo
// Source: http://www.paulund.co.uk/limit-wordpress-search-to-post-titles
function search_by_title_only( $search, &$wp_query )
{
global $wpdb;
if ( empty( $search ) )
return $search; // skip processing - no search term in query
$q = $wp_query->query_vars;
$n = ! empty( $q['exact'] ) ? '' : '%';
<?php
/**
* Limit Search to Video
* @author Bill Erickson
* @link http://www.billerickson.net/wordpress-search-post-type/
*
* @param string search form
* @param string search text
* @param string button text
* @return string modified search form
<?php
//do not add in opening php tag
/**
* Custom Genesis Home Loop with Character Limitation on Excerpt
*
* @package Custom Genesis Home Loop with Character Limitation on Excerpt
* @author Neil Gee
* @link http://wpbeaches.com
* @copyright (c)2014, Neil Gee
@mafsdisseny
mafsdisseny / update_taxonomy_count.sql
Created September 17, 2015 09:35
Wordpress, Update the count parameter for a taxonomy, after data migration. In this case, only specify the post type name, and the associated taxonomies will be updated.
UPDATE wp_term_taxonomy tt
SET count =
(SELECT count(p.ID) FROM wp_term_relationships tr
LEFT JOIN wp_posts p
ON (p.ID = tr.object_id AND p.post_type = 'post_type_name' AND p.post_status = 'publish')
WHERE tr.term_taxonomy_id = tt.term_taxonomy_id
)
@mafsdisseny
mafsdisseny / functions.php
Last active October 15, 2015 08:14
This function returns a string without accents
<?php
//Function that returns a string without accents
//source: http://stackoverflow.com/a/11743977/2841746
function stripAccents($text_to_strip) {
return strtr(utf8_decode($text_to_strip), utf8_decode('àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ'), 'aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY');
}
?>
@mafsdisseny
mafsdisseny / functions.php
Created November 9, 2015 14:36
Creation of a custom post status for WordPress
<?php
// ----------------------------------------------------------------------
// ----------------------- Custom post status ---------------------------
// ----------------------------------------------------------------------
// "premsa" es el post status
// "publicacio" el cpt asociado.
// Create a custom post status
function mafs_new_archive_post_status() {
register_post_status( 'premsa', array(
@mafsdisseny
mafsdisseny / functions.php
Created May 24, 2015 09:47
Add genesis-structural-wrap and filter it through a template
<?php
// First we include it in the genesis-structural-wrap genesis declaration
add_theme_support( 'genesis-structural-wraps', array(
'header',
// 'nav',
// 'subnav',
'site-inner',
'footer-widgets',
'page-header-img', //here is it
'footer'
@mafsdisseny
mafsdisseny / functions.php
Last active February 12, 2016 08:53
Display the advanced tools bar of tiny_mce by default in the WordPress visual editor.
<?php
function show_advanced_tools_bar_tiny_mce( $args ) {
$args['wordpress_adv_hidden'] = false;
return $args;
}
add_filter( 'tiny_mce_before_init', 'show_advanced_tools_bar_tiny_mce' );
@mafsdisseny
mafsdisseny / functions.php
Created May 20, 2016 12:17
Función para imprimir el formulario adecuado dependiendo del idioma. Usa CF7 y Polylang. Requiere crear los formularios siguiendo unas normas de sintaxis.
<?php
// Esta función permite imprimir el formulario adecuado dependiendo del idioma.
// Lo único que hay que tener en cuenta es que cuando creamos el título del formulario
// Hay que hacerlo siguiendo esta norma: "nombre del formulario" + " __" + slug del idioma.
// Ejemplo: ESP: "formulario __es", CAT: "formulario __ca", ENG: "formulario __en"
// En este ejemplo concreto, habría que llamar la función así:
// mafs_print_currentlang_form( 'formulario' );
function mafs_print_currentlang_form( $form_name ) {