Skip to content

Instantly share code, notes, and snippets.

@tacensi
tacensi / WP Get Post by ID
Created March 12, 2018 21:00
WP Get Post by ID
echo apply_filters( 'the_content', get_post_field('post_content', $my_postid ) );
@tacensi
tacensi / WP Nav Menu
Created March 12, 2018 18:55
WP Nav Menu
$args = array(
'theme_location' => 'main',
'menu' => '',
'container' => '',
'container_class' => '',
'container_id' => '',
'menu_id' => '',
'menu_class' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
@tacensi
tacensi / WP Custom Embed
Created March 12, 2018 17:12
WP Custom Embed, to add responsive markup
// Modifica o html do video embebedado para ficar responsivo
add_filter( 'embed_oembed_html','oembed_result', 10, 3 );
function oembed_result( $html, $url, $args ) {
if( strstr( $url, 'youtu' ) ){
$video_pattern = '~(?:http|https|)(?::\/\/|)(?:www.|)(?:youtu\.be\/|youtube\.com(?:\/embed\/|\/v\/|\/watch\?v=|\/ytscreeningroom\?v=|\/feeds\/api\/videos\/|\/user\S*[^\w\-\s]|\S*[^\w\-\s]))([\w\-]{11})[a-z0-9;:@#?&%=+\/\$_.-]*~i';
$video_id = ( preg_replace( $video_pattern, '$1', $url ) );
$html = '<div class="video-container"><iframe src="https://www.youtube.com/embed/' . $video_id . '" frameborder="0" allowfullscreen';
foreach ( $args as $key => $value ) {
@tacensi
tacensi / Custom link shortcode
Created March 12, 2018 17:12
Custom link shortcode, for onclick functionality
@tacensi
tacensi / WP Custom MCE Buttons
Created March 12, 2018 17:11
WP Custom MCE Buttons
// Acrescentando botões de estilo no
add_filter( 'mce_buttons_2', 'my_mce_buttons_2' );
function my_mce_buttons_2( $buttons ) {
array_unshift( $buttons, 'styleselect' );
return $buttons;
}
add_filter( 'tiny_mce_before_init', 'my_mce_before_init' );
function my_mce_before_init( $settings ) {
@tacensi
tacensi / Change post labels
Last active March 12, 2018 17:10
Change post labels
// Modificando o nome dos Posts para Produtos
function mg_change_post_menu_label() {
global $menu;
global $submenu;
$menu[5][0] = 'Produtos';
$submenu['edit.php'][5][0] = 'Produtos';
$submenu['edit.php'][10][0] = 'Adicionar produto';
}
function mg_change_post_object_label() {
@tacensi
tacensi / ACF Options Page
Created March 8, 2018 19:17
ACF Options Page
if( function_exists('acf_add_options_page') ) {
$args = array(
'page_title' => 'Opções',
/* (string) The title displayed in the wp-admin sidebar. Defaults to page_title */
'menu_title' => '',
/* (string) The slug name to refer to this menu by (should be unique for this menu).
Defaults to a url friendly version of menu_slug */
'menu_slug' => '',
Log level set to 287
GNU LilyPond 2.18.2
Relocation: from PATH=/home/tacensi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/tacensi/bin:/usr/lib/wine/bin:/sbin:/usr/sbin:/usr/local/bin:/home/tacensi/.composer/vendor/bin
argv0=lilypond
PATH=/usr/bin (prepend)
Setting PATH to /usr/bin:/home/tacensi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/tacensi/bin:/usr/lib/wine/bin:/sbin:/usr/sbin:/usr/local/bin:/home/tacensi/.composer/vendor/bin
Relocation: compile datadir=, new datadir=/usr/share/lilypond//2.18.2
Relocation: framework_prefix=/usr/bin/..
Setting INSTALLER_PREFIX to /usr/bin/..
PATH=/usr/bin/../bin (prepend)
@tacensi
tacensi / select UF
Created November 9, 2016 19:48
Select com estados do Brasil
<select name="uf" id="uf">
<option value="">Selecione</option>
<option value="AC">AC</option>
<option value="AL">AL</option>
<option value="AM">AM</option>
<option value="AP">AP</option>
<option value="BA">BA</option>
<option value="CE">CE</option>
<option value="DF">DF</option>
<option value="ES">ES</option>
@tacensi
tacensi / jquery.validate.cnpj.js
Created April 26, 2016 20:13 — forked from ricardoriogo/jquery.validate.cnpj.js
CNPJ validation for jQuery Validate
jQuery.validator.addMethod("cnpj", function(cnpj, element) {
var numeros, digitos, soma, resultado, pos, tamanho,
digitos_iguais = true;
if (cnpj.length < 14 && cnpj.length > 15)
return false;
for (var i = 0; i < cnpj.length - 1; i++)
if (cnpj.charAt(i) != cnpj.charAt(i + 1)) {