Skip to content

Instantly share code, notes, and snippets.

<?php
$author_name = get_the_author_meta('display_name');
?>
<div>
Published by
<span itemprop="author" itemscope itemtype="http://schema.org/Person">
<a href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID'))); ?>" itemprop="url">
<span itemprop="name"><?php echo esc_html($author_name); ?></span>
</a>
@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 )
@Dianakc
Dianakc / attachment_meta.php
Created October 19, 2013 02:37
Metadados em anexos
<?php
add_filter('attachment_fields_to_edit', 'estilo_legenda_edit', 10, 2);
add_filter('attachment_fields_to_save', 'estilo_legenda_save', 10, 2);
function estilo_legenda_edit($form_fields, $post) {
$value = get_post_meta($post->ID, '_captionstyle', true);
$form_fields['captionstyle'] = array(
'label' => __('Estilo da legenda'),
'input' => 'html',
@Dianakc
Dianakc / get_names.php
Created October 19, 2013 02:34
Obtém somente o nome dos termos, sem link, separado por vírgulas
<?php
$terms = get_the_terms ($post->id, 'skills');
if ( !is_wp_error($terms)) : ?>
<?php
$skills_links = wp_list_pluck($terms, 'name');
$skills_yo = join(", ", $skills_links);
?>