Skip to content

Instantly share code, notes, and snippets.

View mauriciogofas's full-sized avatar

Mauricio Gofas mauriciogofas

View GitHub Profile
@mauriciogofas
mauriciogofas / functions.php
Last active September 16, 2015 03:55
Diferentes menus para usuários logados e não logados
<?php
// Diferentes menus para usuários logados e não logados
function my_wp_nav_menu_args( $args = '' ) {
if( is_user_logged_in() ) {
$args['menu'] = 'logado';
} else {
$args['menu'] = 'Naologado';
}
@mauriciogofas
mauriciogofas / functions.php
Created February 5, 2015 17:12
WP Automatic Year, Copyright and Site Name linked to Home
//Automatic Year, Copyright and Site Name linked to Home
<span>&copy; <?php echo date("Y") ?> <a href="<?php bloginfo('siteurl'); ?>/" title="<?php bloginfo('description'); ?>"><?php bloginfo('name'); ?></a></span>
@mauriciogofas
mauriciogofas / functions.php
Created February 5, 2015 17:06
Tradução Ou Substituição de textos WP
<?php
// Tradução Ou Substituição de textos
function change_translate_text( $translated ) {
$text = array(
'Comments' => 'Comentários',
'Next' => 'Próximo',
'Previous' => 'Anterior',
);
$translated = str_ireplace( array_keys($text), $text, $translated );
return $translated;
@mauriciogofas
mauriciogofas / functions.php
Created February 5, 2015 17:04
Open Comment Author Link In New Window
<?php
// Open Comment Author Link In New Window
add_filter( 'get_comment_author_link', 'open_comment_author_link_in_new_window' );
function open_comment_author_link_in_new_window( $author_link ) {
return str_replace( "<a", "<a target='_blank'", $author_link );
}
// END Open Comment Author Link In New Window
@mauriciogofas
mauriciogofas / functions.php
Created February 5, 2015 17:03
Righlight Current parent and child menu
<?php
//Righlight Current parent and child menu
add_filter('nav_menu_css_class', 'add_active_class', 10, 2 );
function add_active_class($classes, $item) {
if( in_array( 'current-menu-item', $classes ) ||
in_array( 'current-menu-ancestor', $classes ) ||
in_array( 'current-menu-parent', $classes ) ||
in_array( 'current_page_parent', $classes ) ||
@mauriciogofas
mauriciogofas / functions.php
Created February 5, 2015 16:39
Primeira imagem do post automaticamente como Imagem relacionada
<?php
// Imagem relacionada é a Primeira imagem do post
function ds_get_first_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
@mauriciogofas
mauriciogofas / functions.php
Created February 5, 2015 16:10
Custom wp excerpt length
<?php
//Tamanho do resumo
function new_excerpt_length($length) {
return 160;
}
add_filter('excerpt_length', 'new_excerpt_length');
@mauriciogofas
mauriciogofas / functions.php
Last active August 29, 2015 14:14
Show Thumb of posts in post columns
//Coluna com Imagem Relacionada na lista de posts
if ( !function_exists('fb_AddThumbColumn') && function_exists('add_theme_support') ) {
// for post and page
add_theme_support('post-thumbnails', array( 'post', 'page' ) );
function fb_AddThumbColumn($cols) {
$cols['thumbnail'] = __('Thumbnail');
@mauriciogofas
mauriciogofas / functions.php
Created February 5, 2015 16:05
Remove wp dashboard widgets
<?php
// Remove Dashboard widgets
function remove_dashboard_widgets() {
global $wp_meta_boxes;
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_custom_feed']);
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_drafts']);
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
@mauriciogofas
mauriciogofas / gist:aecfef00e8ac02bbe7a9
Created February 5, 2015 16:03
Custom Capability for especifc wp user
<?php
// Super User
function add_theme_caps() {
//to add capability to user
$user = new WP_User( $user_id = 1 ); //ID of user
$user->add_cap( 'custom_apability');
}
add_action( 'admin_init', 'add_theme_caps');
//