Skip to content

Instantly share code, notes, and snippets.

View f3tusz's full-sized avatar

Farid García f3tusz

View GitHub Profile
@f3tusz
f3tusz / ACF Responsive Background Image.md
Created March 28, 2022 03:09 — forked from megclaypool/ACF Responsive Background Image.md
Responsive Images (with srcset and sizes) in WordPress (PHP) This is for use in a php template, taking advantage of built-in WP image functions to generate a fancy responsive image tag, complete with srcset and sizes. Set a variable equal to the res

This is Jason's Responsive Background Image Twig Macro translated into PHP for use with ACF image fields:

<?php function responsive_ACF_background_image($image, $display_style, $css_path) {
  $retina_style = $display_style . "2x";
  echo "<style>
      $css_path {
          background-image: url(\"" . $image[sizes][$display_style] . "\");
      }
 @media
@f3tusz
f3tusz / apprch-wp-srcset.php
Created November 28, 2021 23:24 — forked from piperhaywood/apprch-wp-srcset.php
WordPress function to create HTML5 image element with 'srcset' and 'sizes' attributes for JPEGs and PNGs. Paste in to functions.php for use elsewhere in theme.
/**
* WordPress function to create HTML5 image element with 'srcset' and 'sizes' attributes for JPEGs and PNGs.
* Paste in to functions.php for use elsewhere in theme. Images in 'srcset' are created from all WordPress registered image sizes.
* Mime types 'image/jpg', 'image/png', and 'image/gif' are returned appropriately.
*
* @author Piper Haywood <[email protected]>
* @link http://piperhaywood.com
* @link https://gist.github.com/piperhaywood/96ac07ea5f4999512275
*
* @example https://gist.github.com/piperhaywood/686cc0c788bd9fc3fa6e
@f3tusz
f3tusz / acf_wysiwyg_height.php
Created November 28, 2021 06:12 — forked from stianandreassen/acf_wysiwyg_height.php
Add a height field to ACF WYSIWYG Field
<?php
/**
* Add height field to ACF WYSIWYG
*/
function wysiwyg_render_field_settings( $field ) {
acf_render_field_setting( $field, array(
'label' => __('Height of Editor'),
'instructions' => __('Height of Editor after Init'),
'name' => 'wysiwyg_height',
'type' => 'number',
@f3tusz
f3tusz / nav-walker.php
Created November 25, 2021 05:41 — forked from wturnerharris/nav-walker.php
Use custom walker to modify wp_nav_menu()
<?php
/* **** USAGE ****
* <?php wp_nav_menu( array(
* 'walker' => new custom_walker_nav_menu()
* )); ?>
*/
class custom_walker_nav_menu extends Walker {
var $tree_type = array( 'post_type', 'taxonomy', 'custom' );
@f3tusz
f3tusz / custom-nav-walker-usage.php
Created November 24, 2021 06:32 — forked from kosinix/custom-nav-walker-usage.php
WordPress: Using a custom nav walker to create navigation menus in plain <a> tags. That is the <ul> and <li> tags are not present. Very useful if you want to create simple links that can be centered with a simple text-align:center on the containing element.
<?php
// In your template files like footer.php
// The items_wrap value ('%3$s') removes the wrapping <ul>, while the custom walker (Nav_Footer_Walker) removes the <li>'s.
wp_nav_menu(array('items_wrap'=> '%3$s', 'walker' => new Nav_Footer_Walker(), 'container'=>false, 'menu_class' => '', 'theme_location'=>'footer', 'fallback_cb'=>false ));
?>
@f3tusz
f3tusz / twitter.php
Created July 6, 2021 13:15 — forked from twandy/twitter.php
Get Tweets with PHP and JSON
<?php
// Get Twitter Timeline
$twitter = json_decode(file_get_contents('http://api.twitter.com/1/statuses/user_timeline.json?screen_name=twandy&include_rts=0&count=1&exclude_replies=1', true));
if($twitter != '') // If a Tweet is found
{
// Get Tweet date & convert to desired format
$twitter_created = date('jS F, Y', strtotime($twitter[0]->created_at));
// Strip HTML from Tweet
@f3tusz
f3tusz / srcset.php
Created April 5, 2021 22:11 — forked from verticalgrain/srcset.php
Wordpress srcset snippet for ACF image field
<?php
// Use an ACF image field
// Set the 'return value' option to "array" (this is the default)
// This example uses three image sizes, called medium, medium_large, thumbnail
$imageobject = get_field('image');
if( !empty($imageobject) ):
echo '<img alt="' . $imageobject['title'] . '" src="' . $imageobject['sizes']['medium'] . '" srcset="' . $imageobject['sizes']['medium_large'] .' '. $imageobject['sizes']['medium_large-width'] .'w, '. $imageobject['sizes']['medium'] .' '. $imageobject['sizes']['medium-width'] .'w, '. $imageobject['sizes']['thumbnail'] .' '. $imageobject['sizes']['thumbnail-width'] .'w">';
endif;
?>
@f3tusz
f3tusz / acf-wysiwyg-style-select.php
Created April 2, 2021 02:11 — forked from brombal/acf-wysiwyg-style-select.php
Custom Styles Dropdown for ACF Wysiwyg Editors (WP Plugin)
<?php
/**
* Plugin Name: ACF Wysiwyg Style Select
* Description: Custom style select boxes for ACF Wysiwyg editors.
* Author: Alex Brombal
* Author URI: http://www.brombal.com
* Version: 1.1
* License: MIT
*/
@f3tusz
f3tusz / hide-editor.php
Created March 27, 2021 04:57 — forked from ramseyp/hide-editor.php
Hide the content editor for certain pages in WordPress
<?php
/**
* Hide editor on specific pages.
*
*/
add_action( 'admin_init', 'hide_editor' );
function hide_editor() {
// Get the Post ID.
@f3tusz
f3tusz / wp-query-ref.php
Created March 7, 2021 14:21 — forked from luetkemj/wp-query-ref.php
WP: Query $args
// This gist is now maintained on github at https://github.com/luetkemj/wp-query-ref
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.github.io
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/4.9.4/src/wp-includes/query.php
*/