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 / remove_css.php
Created December 17, 2014 02:29
Remove jetpack styles
<?php
function remove_jetpack_styles(){
wp_deregister_style('AtD_style'); // After the Deadline
wp_deregister_style('jetpack-carousel'); // Carousel
wp_deregister_style('grunion.css'); // Grunion contact form
wp_deregister_style('the-neverending-homepage'); // Infinite Scroll
wp_deregister_style('infinity-twentyten'); // Infinite Scroll - Twentyten Theme
wp_deregister_style('infinity-twentyeleven'); // Infinite Scroll - Twentyeleven Theme
wp_deregister_style('infinity-twentytwelve'); // Infinite Scroll - Twentytwelve Theme
wp_deregister_style('noticons'); // Notes
@Dianakc
Dianakc / test_if_meta.php
Created June 13, 2014 15:21
Testa se há valor na chave de metadados
<?php
function test_if_meta($arr, $key, $before = '', $after = '') {
if ($text = $arr[$key][0])
return $before . $text . $after;
}
@Dianakc
Dianakc / recent_posts.php
Created June 13, 2014 15:16
Shortcode posts recente
<?php
function my_recent_posts_shortcode( $atts ) {
extract( shortcode_atts( array( 'limit' => 5 ), $atts ) );
$q = new WP_Query( 'posts_per_page=' . $limit );
$list = '<ul class="recent-posts">';
while ( $q->have_posts() ) {
$q->the_post();
@Dianakc
Dianakc / css_admin.php
Created June 12, 2014 20:35
Adiciona css ao admin
<?php
add_action('admin_head', 'my_custom_fonts');
function my_custom_fonts() {
echo '<style>
#breedsdiv {display:none;}
</style>';
}
@Dianakc
Dianakc / add_cmb.php
Created June 12, 2014 19:41
Adicionando o CMB :)
<?php
if (is_admin()) {
add_action( 'init', 'cmb_showcase_load_metabox' );
}
function cmb_showcase_load_metabox() {
require_once( 'includes/metabox/example-functions.php' );
require_once( 'includes/metabox/init.php' );
@Dianakc
Dianakc / custom_post_save.php
Created June 12, 2014 19:39
Ação save post para tipos personalizados
<?php
function my_custom_save_post( $post_id ) {
// do stuff here
}
add_action( 'save_post_membros', 'my_custom_save_post' );
@Dianakc
Dianakc / recent_posts_mod.php
Created April 25, 2014 18:15
Remove/modifica o widget de Posts Recentes
<?php
add_filter('widget_posts_args','modify_widget');
function modify_widget() {
$r = array( 'cat' => '6' );
return $r;
}
@Dianakc
Dianakc / snipet_ano_mes.php
Created April 22, 2014 04:35
Mostra arquivo separado por ano/mês
<ul>
<?php
global $wpdb;
$limit = 0;
$year_prev = null;
$months = $wpdb->get_results("SELECT DISTINCT MONTH( post_date ) AS month , YEAR( post_date ) AS year, COUNT( id ) as post_count FROM $wpdb->posts WHERE post_status = 'publish' and post_date <= now( ) and post_type = 'post' GROUP BY month , year ORDER BY post_date DESC");
foreach($months as $month) :
$year_current = $month->year;
if ($year_current != $year_prev){
if ($year_prev != null){?>
@Dianakc
Dianakc / get_menu.php
Created March 15, 2014 02:27
Obtém os itens do menu de um theme location. Ex: pega os itens que estão no menu Rodapé, não os itens de menu baseando-se no menu que tiver criado.
<?php
$menuParameters = array(
'theme_location' => 'menu_d', // o nome do local! De quando se cria locais!
'container' => false,
'echo' => false,
'items_wrap' => '%3$s',
'depth' => 0,
);