Skip to content

Instantly share code, notes, and snippets.

View vaakash's full-sized avatar
🏠
Working from home

Aakash Chakravarthy vaakash

🏠
Working from home
View GitHub Profile
@vaakash
vaakash / id-heading.php
Created February 7, 2024 18:17
Adding ID to headings in WordPress
<?php
/**
* Adds "id" attribute to heading tags in WordPress post content using the "the_content" filter and regex.
*/
function anchor_headings( $content ) {
$content = preg_replace_callback( '/(\<h[2-3](.*?))\>(.*)(<\/h[2-3]>)/i', function( $matches ) {
if ( ! stripos( $matches[0], 'id=' ) ){
$slug = sanitize_title( $matches[3] );
@vaakash
vaakash / conditional-shortcode.php
Created January 5, 2023 17:33
Create a shortcode which will conditional print shortcoder shortcode
<?php
/* Create a shortcode which will conditional print shortcoder shortcode */
function sc_condition_function($args){
$category = get_the_category();
$firstCategory = $category[0]->cat_name;
if( $firstCategory = 'my_category' ){
echo do_shortcode( '[sc name="sc1"]' );
@vaakash
vaakash / exclude-iframe-super-rss-reader.php
Created January 23, 2022 19:48
Excludes iframe from beign stripped from the Super RSS Reader feed item content
<?php
function srr_youtube_video( $html, $feed_url, $feed_item ){
$content = $feed_item->get_content();
$html[ 'description' ] = $content;
return $html;
}
add_filter( 'srr_mod_item_html', 'srr_youtube_video', 10, 3 );
@vaakash
vaakash / share-buttons-super-rss-reader.php
Created January 23, 2022 18:39
Adding share buttons to Super RSS Reading
<?php
// This code adds "Share buttons" to the feed items displayed using Super RSS Reader WordPress plugin. The RSS feed items are shared using AddToAny and Flipboard services.
// It uses Super RSS Reader's filter https://www.aakashweb.com/docs/super-rss-reader/actions-filters/#srr_mod_item_html to modify the output
add_filter( 'srr_mod_item_html', 'srr_share_buttons', 10, 3 );
function srr_share_buttons( $html, $feed_url, $feed_item ){
$item_url = $feed_item->get_permalink();
$share_link = 'https://www.addtoany.com/share?url=' . $item_url;
@vaakash
vaakash / shortcodes.php
Created August 27, 2020 19:06
Support for WP Socializer to consider page info with templates
<?php
/**
* Shortcodes handler
*
**/
class WPSR_Shortcodes{
public static function init(){
@vaakash
vaakash / shortcoder-woocommerce-parameters.php
Last active July 25, 2020 19:28
Support to add woocommerce related parameters in shortcoder WordPress plugin
<?php
function shortcoder_woocommerce_params( $params ){
$params['wc_info'] = array(
'name' => __( 'WooCommerce information', 'shortcoder' ),
'icon' => 'cart',
'params' => array(
'sku' => __( 'Product SKU', 'shortcoder' ),
'price' => __( 'Product price', 'shortcoder' ),