Skip to content

Instantly share code, notes, and snippets.

@marcelo2605
marcelo2605 / input.scss
Created June 30, 2021 18:01
Generated by SassMeister.com.
@for $i from 1 through 13 {
@media (min-width: 576px) {
.grid-start-sm-#{$i} {
grid-column-start: #{$i};
}
.grid-end-sm-#{$i} {
grid-column-end: #{$i};
background: blue;
@marcelo2605
marcelo2605 / functions.php
Created March 12, 2021 11:57
Use Lite YouTube in WordPress
/**
* Use Lite YouTube in posts embeds
* https://github.com/paulirish/lite-youtube-embed
*/
add_filter('embed_oembed_html', function($cached_html, $url, $attr, $post_id) {
$querystring = parse_url($url, PHP_URL_QUERY);
parse_str($querystring, $params);
if (isset($params['v'])) {
$format = '<lite-youtube videoid="%s"></lite-youtube>';
@marcelo2605
marcelo2605 / functions.php
Created January 11, 2019 16:54
Register new order status on WooCommerce
/**
* Register new status
*
**/
add_action('init', function() {
register_post_status('wc-producao', array(
'label' => 'Em produção',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
@marcelo2605
marcelo2605 / pagination.php
Created January 4, 2019 13:24
Pagination with custom wp_query
// more options here: https://codex.wordpress.org/Function_Reference/paginate_links
public static function getPagination($pages = null)
{
$args = array(
'prev_next' => false,
'type' => 'list'
);
if ($pages) {
@marcelo2605
marcelo2605 / index.html
Created December 20, 2018 14:57
Open and close multiple dropdowns
<div class="dropdown">
<button class="dropdown-toggle" type="button">Dropdown</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Item 1</a>
<a class="dropdown-item" href="#">Item 2</a>
</div>
</div>
@marcelo2605
marcelo2605 / functions.php
Created September 21, 2018 11:33
Filter "Recent posts" widget to show only posts that have the same category that current post.
/**
* Add parameter to Recent post widget
*/
add_filter('widget_posts_args', function($params){
$categories = get_the_category(get_the_ID());
$params['cat'] = $categories[0]->term_id;
return $params;
});
@marcelo2605
marcelo2605 / functions.php
Created August 2, 2018 16:09
Replace <p> by <figure> around images and make tables responsive using table-responsive Bootstrap class
/**
* Replace <p> by <figure> around images and make tables responsive using table-responsive Bootstrap class
*/
add_filter( 'the_content', function($content) {
$content = preg_replace('/<p>\\s*?(<a .*?><img.*?><\\/a>|<img.*?>)?\\s*<\\/p>/s', '<figure class="content-image">$1</figure>', $content);
// Run only if is a singular post page
if (is_singular()) {
$content = preg_replace("/(<table(?s).*<\/table>)/i", "<div class='table-responsive'>$1</div>", $content);
}
@marcelo2605
marcelo2605 / functions.php
Created June 22, 2018 17:33
Add an audio description with the audio player.
add_filter('wp_audio_shortcode', function ($html, $atts, $audio, $post_id, $library) {
$media_id = attachment_url_to_postid($atts['mp3']);
if (0 !== $media_id) {
$content = get_post_field('post_content', $media_id);
$content = apply_filters('the_content', $content);
if (!empty($content)) {
$html = $html.'<div class="audio-description">'.$content.'</div>';
}
}
require_once('PagSeguroLibrary/PagSeguroLibrary.php');
function generate_pagseguro($user_id){
// Instantiate a new payment request
$paymentRequest = new PagSeguroPaymentRequest();
// Set the currency
$paymentRequest->setCurrency("BRL");
<?php
/**
* BuddyPress - Members Home
*
* @package BuddyPress
* @subpackage bp-legacy
*/
?>