add_rewrite_rule isnt working, not getting added to rules array, why?

Try this. You also don’t want to include $wp_rewrite->flush_rules() inside your function as that would flush on every page load. add_action(‘rewrite_rules_array’, ‘new_rewrite_rules’); function new_rewrite_rules($rules){ $newrules = array(); $newrules[ ‘^lists/([^/]*)/([^/]*)/?’ = ‘index.php?lists=$matches[1]&post=$matches[2]’; return $newrules + $rules; } If you want to flush the rules only once then try this: add_action(‘init’, ‘flush_new_rule’); function flush_new_rule(){ global $wp_rewrite; if(is_array(get_option(‘rewrite_rules’)) … Read more

How to filter out shortcode when displaying the_excerpt() in the loop?

try this add_filter( ‘get_the_excerpt’, ‘strip_shortcodes’, 20 ); or try this edit echo strip_shortcodes( get_the_excerpt() ); if shortcode is not register with wordpress function add_shortcode add_filter( ‘the_excerpt’, ‘remove_shortcodes_in_excerpt’, 20 ); function remove_shortcodes_in_excerpt( $content){ $content = strip_shortcodes($content); $tagnames = array(‘box’, ‘alert’); // add shortcode tag name [box]content[/box] tagname = box $content = do_shortcodes_in_html_tags( $content, true, $tagnames ); … Read more

How do I remove all hyperlinks that begin with a #?

Inspired by @Samuel Elh, but accounting for single or double quoted attributes and a href that might not be the first attribute of an anchor: function wpse_227315_strip_hyperlinks( $content ) { preg_match_all( ‘!<a[^>]*? href=[\'”]#[^<]+</a>!i’, $content, $matches ); foreach ( $matches[0] as $link ) $content = str_replace( $link, strip_tags( $link ), $content ); return $content; } add_filter( … Read more

Wrap First Character after in a tag

The major issue is just that you have a positive lookbehind but no capture group so \1 or $1 isn’t a usable variable. Fix your regex to provide the capture group: ‘/(?<=\<\/h3\>\n<p>)(.)/’ then reference as $1. ob_start();?> <h3>Heading</h3> <p>Paragraph</p> <p>Paragraph2</p> <?php $search = ob_get_clean(); $result = preg_replace( ‘/(?<=\<\/h3\>\n<p>)(.)/’, ‘<span class=”dropcap”>$1</span>’, $search );

How to properly rewrite url by custom var

So, first off, never flush rewrite rules on every page load. Better to do it on plugin activation one time. Step 1: add the rewrite rule: add_action( ‘init’, ‘wpse26555_add_rewrite’ ); function wpse26555_add_rewrite() { // You should probably rewrite to index.php instead of shop.php? add_rewrite_rule( ‘/shop/brand/([^/]+)/?$’, ‘index.php?brand=$matches[1]’, ‘top’ ); } Step 2: add the query var … Read more