Skip to content

Instantly share code, notes, and snippets.

@Dianakc
Dianakc / wp_pluck.php
Last active September 10, 2015 15:36
Obter o ID (qualquer campo) de um único post
<?php
$myposts = get_posts('category_name=carros&posts_per_page=1'); //exemplo de um post da categoria "Carros"
$r = wp_list_pluck( $myposts, 'ID' ); //no caso ID, pode ser outros campos
echo 'O ID do post:'.$r[0]; //usar [0]
@Dianakc
Dianakc / resp_twit.php
Created February 14, 2014 21:51
Força o embed de twits ser responsível
<?php
add_filter('oembed_result','twitter_no_width',10,3);
function twitter_no_width($html, $url, $args) {
if (false !== strpos($url, 'twitter.com')) {
$html = str_replace('width="550"','',$html);
}
return $html;
}
@Dianakc
Dianakc / remove_cat.php
Created February 12, 2014 17:37
Remove um ou mais nomes de categorias de the_category
<?php
function the_category_filter($thelist,$separator=' ') {
if(!defined('WP_ADMIN')) {
$exclude = array('Blog'); /* nomes/slugs da cats */
$cats = explode($separator,$thelist);
$newlist = array();
foreach($cats as $cat) {
@Dianakc
Dianakc / body_class.php
Created December 13, 2013 20:50
Adiciona uma classe á tag body, no exemplo page-slug
<?php
add_filter('body_class','my_class_names');
function my_class_names($classes) {
$classes[] = 'page-'.get_query_var('pagename');
// return the $classes array
return $classes;
}
@Dianakc
Dianakc / replace_w.php
Created December 10, 2013 04:28
Substitui strings por outra (dinamicamente)
<?php
function replace_text_wps($text){
$replace = array(
// 'WORD TO REPLACE' => 'REPLACE WORD WITH THIS'
'thesis' => '<a href="http://mysite.com/myafflink">thesis</a>',
'studiopress' => '<a href="http://mysite.com/myafflink">studiopress</a>'
);
$text = str_replace(array_keys($replace), $replace, $text);
return $text;
@Dianakc
Dianakc / parentpage_title.php
Created December 8, 2013 03:05
Mostra o título da página mãe nas páginas filhas
<?php
$parent_title = get_the_title($post->post_parent);
echo $parent_title;
?>
@Dianakc
Dianakc / add_custom_sizes.php
Created October 27, 2013 02:16
Adiciona tamanhos perrsonalizados no seletor de tamanhos do enviador de mídia
<?php
add_filter( 'image_size_names_choose', 'custom_image_sizes_choose' );
function custom_image_sizes_choose( $sizes ) {
$custom_sizes = array(
'featured-image' => 'Featured Image'
);
return array_merge( $sizes, $custom_sizes );
}
@Dianakc
Dianakc / use_parent_cat_template.php
Created October 25, 2013 00:39
Força subcategorias usarem o modelo category-nome.php de suas categorias mães
<?php
// make category use parent category template
function load_cat_parent_template($template) {
$cat_ID = absint( get_query_var('cat') );
$category = get_category( $cat_ID );
$templates = array();
@Dianakc
Dianakc / empty_exccerpt.php
Created October 24, 2013 19:23
Não mostrar conteúdo se Resumo estiver vazio
<?php
add_action( 'init', 'wpse17478_init' );
function wpse17478_init()
{
remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' );
}
@Dianakc
Dianakc / remove_top_cats_chekbox.php
Created October 23, 2013 23:06
Remove a caixa de marcação de categorias top
<?php
add_action( 'admin_footer-post.php', 'wpse_22836_remove_top_categories_checkbox' );
add_action( 'admin_footer-post-new.php', 'wpse_22836_remove_top_categories_checkbox' );
function wpse_22836_remove_top_categories_checkbox()
{
global $post_type;
if ( 'post' != $post_type )