Skip to content

Instantly share code, notes, and snippets.

@eudesgit
eudesgit / wp-generate-custom-feed-rss.php
Last active August 16, 2023 09:08
How to generate custom RSS on WordPress
<?php
/**
* Generating your own custom RSS feed with custom URL and parameters
*/
/**
* Initialise RSS feed
* @see https://developer.wordpress.org/reference/functions/add_feed/
*/
function init_rss_feed_custom( ) {
@eudesgit
eudesgit / wp-slider-revolution-accesibility-fixer.js
Created July 27, 2018 15:37
Script to make WordPress Slider Revolution Plugin slides more accessibile
/**
* Manipulates Slider Revolution HTML to make it more W3C compliant
*
* It's required to meet basic W3C accessibility standards.
* To make it work out, the following Slider Revolutions options have to be filled:
* - Slider title
* - Slider > Link & Seo > Enable Link = Enable
* - Slider > Link & Seo > Link Type = Regular
* - Slider > Slide Link > "The full page URL"
* - Slider > Slide info > A description with the same words from the slider image.
@eudesgit
eudesgit / wp-gutenberg-dynamic-block.js
Created April 3, 2018 18:33
Creates a simple editable WordPress Gutenberg block that is rendered on server side.
/**
* Simple dynamic block sample
*
* Creates a block that doesn't render the save side, because it's rendered on PHP
*/
// Required components
const { __ } = wp.i18n;
const { registerBlockType, RichText } = wp.blocks;
@eudesgit
eudesgit / wp-plugin-gutenberg-block-render.php
Last active June 14, 2018 17:32
A render function for a WordPress Gutenberg block in PHP
<?php
/**
* CALLBACK
*
* Render callback for the dynamic block.
*
* Instead of rendering from the block's save(), this callback will render the front-end
*
* @since 1.0.0
* @param $att Attributes from the JS block
@eudesgit
eudesgit / wp-plugin-gutenberg-server-block.php
Created April 3, 2018 18:25
Registers the scripts and styles to create a WordPress Gutenberg block that is rendered on PHP
<?php
/**
* Registers the dynamic server side block JS script and its styles
*
* @since 1.0.0
* @return void
*/
public function register_dynamic_block_action ( ) {
$block_name = 'block-dynamic';
@eudesgit
eudesgit / wp-gutenberg-inspected-block.js
Last active May 8, 2018 14:09
Creates a simple editable WordPress Gutenberg block with Inspector controls that makes a button link
/**
* Simple editable block with inspection controls
*
* Creates an editable block to make a link button, but with inspection controlls on the sidebar
*/
/**
* Required components
*/
@eudesgit
eudesgit / wp-gutenberg-editable-block.js
Last active May 8, 2018 13:42
Creates a simple editable WordPress Gutenberg block that makes a link
/**
* Simple editable block sample
*
* Creates an editable block to make a link
*/
// Required components
const { __ } = wp.i18n;
const { registerBlockType, RichText, source } = wp.blocks;
@eudesgit
eudesgit / wp-gutenberg-simple-block.js
Last active November 13, 2018 19:01
Creates a simple WordPress Gutenberg block that makes a red title
/**
* Simple block
*
* Creates a simple block that makes a red title
*
* @requires Gutenberg 4.3
*/
// Required components
const { registerBlockType } = wp.blocks; // registerBlockType function that creates a block
@eudesgit
eudesgit / wp-plugin-gutenberg-block.php
Last active November 13, 2018 18:58
Registers the scripts and styles to create a WordPress Gutenberg block
<?php
/**
* Registers a Gutenberg block JS script and its styles
*
* @since 1.0.0
* @return void
*/
public function register_block_action ( ) {
$block_name = 'my_block';
@eudesgit
eudesgit / wp-plugin-filtering-rendering-page-template.php
Created February 13, 2018 19:36
WordPress: How to filter the Page Template that is being rendered.
<?php
/**
* template_include Filter callback
*
* Include plugin's template if there's one chosen for the rendering page
*
* @param string $template path
* @return string $template path
*/
public function add_template_filter ( $template ) {