Skip to content

Instantly share code, notes, and snippets.

<?php
/*
* Verificar se há uma determinada string no conteúdo de um post do WordPress
*/
function is_string_in_content( $string )
{
global $post;
if ( strpos( get_post_field('post_content', $post->ID), $string ) !== false)
return true;
<?php get_header(); ?>
[...]
<ul class="lista-parceitos">
<?php
$prefix = '_cmb2_';
$grupo_campos_parceiro = get_post_meta($post->ID, $prefix.'grupo_campos_parceiro', true);
foreach ($grupo_campos_parceiro as $key => $value) {
@marcelotorres
marcelotorres / functions.php
Last active January 5, 2017 16:39
Criando uma página de parceiros no WordPress com CMB2 -> http://www.marcelotorresweb.com/criando-pagina-parceiros-com-cmb2-worpdress/
<?php
function cmb2_parceiros_field_metaboxes() {
// Start with an underscore to hide fields from custom fields list
$prefix = '_cmb2_';
// Cria o Metabox
$cmb2_parceiro = new_cmb2_box( array(
'id' => $prefix . 'parceiro_configs_metabox',
'title' => 'Cadastrar parceiros',
<?php
add_action( 'add_meta_boxes', array ( 'tinyMCE_for_excerpt', 'switch_boxes' ) );
/**
* Replaces the default excerpt editor with TinyMCE.
*/
class tinyMCE_for_excerpt
{
/**
* Replaces the meta boxes.
<?php
/**
* Configura o metabox e os campos personalizados
*/
function cmb2_referencias_metaboxes() {
// Recomnedado usar um prefixo no id do campo
$prefix = '_cmb2_';
// Inicializa o metabox dos campos personalizados
@marcelotorres
marcelotorres / functions.php
Created November 26, 2016 14:47 — forked from grappler/functions.php
Loading theme and plugin translations in WordPress - https://ulrich.pogson.ch/load-theme-plugin-translations
<?php
function theme_name_setup(){
$domain = 'theme-name';
// wp-content/languages/theme-name/de_DE.mo
load_theme_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain );
// wp-content/themes/child-theme-name/languages/de_DE.mo
load_theme_textdomain( $domain, get_stylesheet_directory() . '/languages' );
// wp-content/themes/theme-name/languages/de_DE.mo
@marcelotorres
marcelotorres / get-attachment-id-by-guid.php
Created November 24, 2016 22:42
WordPress - get attachment id by guid/URL
<?php
// Pegar id do arquivo/imagem pela url
function get_attachment_id_by_guid( $attachment_url = '' ) {
global $wpdb;
$attachment_id = false;
// If there is no url, return.
if ( '' == $attachment_url )
return;
@marcelotorres
marcelotorres / only-admin-in-dashboard.php
Created November 24, 2016 22:30
Disable Access to the WordPress Dashboard for Non-Admins
<?php
// Desativar acesso ao painel do WordPress para não-administradores
add_action('admin_init', 'only_admin_in_dashboard');
function only_admin_in_dashboard() {
if (!current_user_can('manage_options') && $_SERVER['DOING_AJAX'] != '/wp-admin/admin-ajax.php') {
wp_redirect(home_url()); exit;
}
}
@marcelotorres
marcelotorres / body-classes-plus.php
Created November 24, 2016 12:55
Filter to put more classes in the body class function, in the example below you are adding the "post slug"
<?php
/*
* Filtro para colocar mais classes na função body class, no exmeplo abaixo está adicionando o "slug do post"
*/
add_filter('body_class', 'body_classes_plus');
function body_classes_plus($classes) {
global $post;
$classes[] = (!is_home()) ? $post->post_name : ''; // Slug do post
@marcelotorres
marcelotorres / foundation-wp-enqueue-script.php
Last active November 24, 2016 12:56
Load foundation 6 scripts
<?php
/*
* Carregar JS e CSS
*/
function load_frontend_scripts(){
if(!is_admin()){
//jQuery
wp_deregister_script( 'jquery' );