help to remove last trailing slash using add_rewrite_rule

Replace all your above code with the one below: <?php function master_load_ads_txt_template_include( $template ) { $is_load_ads_txt = (bool) get_query_var( ‘ads-txt’ ); if ( $is_load_ads_txt ) { $template = locate_template( ‘template-parts/ads-txt.php’ ); } return $template; } add_filter( ‘template_include’, ‘master_load_ads_txt_template_include’ ); function master_load_ads_txt_rewrite() { add_rewrite_rule( ‘ads.txt’, ‘index.php?ads-txt=true’, ‘top’ ); // The line below doesn’t work and it’s … Read more

Bulk append URL (add word to slug)

Here is your code: if ( isset($_GET[‘slug-update’]) ) { $posts = get_posts(); foreach($posts as $singlepost) { if($singlepost->post_status === ‘publish’){ $post_id = $singlepost->ID; $current_slug = $singlepost->post_name; $updated_slug = $current_slug . ‘-word’; } wp_update_post( array( ‘ID’ => $post_id, ‘post_name’ => $updated_slug ) ); } die(‘Slug Updated’); } Add this to your theme’s function.php. Then run this with … Read more

How to Add Shortcode to html img code?

You cannot use Shortcodes in attributes since 4.2.3, for security reasons. See the announcement (emphasis mine): Earlier today, we released WordPress 4.2.3, which includes a relatively large security fix that affects the Shortcode API. Due to the nature of the fix – as is often the case with security fixes – we were unable to … Read more

Clean Custom URL for Serach + Custom Taxonomy

With Slam’s kind tip to use query-monitor plugin, I could figure out what the problem was. Apparently the url /search/foo/filter/bar also fits the “general search” rewrite-rule. Makes sense, thinking about it– (.+) technically matches /foo/filter/bar aswell. So I could improve (.+) by excluding /s? But I found an easier solution! In hope “first match wins” … Read more

WordPress rewrite url

But we are not limited to default formats, as WordPress allows users to customize the pretty permalink format by setting one or more structure tags. The custom structure option allows to set a highly customized pretty permalink format The custom structure option allows to set a highly customized pretty permalink format

WP in subfolder hidden by htaccess, but media links show the subfolder

One option is to explicitly move the wp-content folder one level up so it resides at /public_html/wp-content by defining WP_CONTENT_DIR in wp-config.php. For this I’d recommend something more like the second method described in Giving WordPress Its Own Directory. Editing wp-config.php has an example for the WP_CONTENT_DIR change. The resulting directory structure (relative to public_html … Read more

How to change custom post type, blog post and page permalink by template?

modify post works different than modify page than modify custom post type permalink. Here is how to modify all of them within your template code only and give the whole page a custom url structure. modify custom post type permalink add_action( ‘init’, ‘rewriteCustomPostUrls’ ); function rewriteUrls() { global $wp_rewrite; $version = ‘/product/%product%/version/%version%’; $wp_rewrite->add_rewrite_tag( “%product%”, ‘([^/]+)’, … Read more

SOLVED Custom Add rewrite rule and Get string

The values parsed out of internal rewrites don’t end up in GET, you have to use get_query_var(‘search_location’) instead. If you have code that you can’t edit that relies on GET, you can try to set them manually- function wpd_foo_get_param() { if( false !== get_query_var( ‘search_location’ ) ){ $_GET[‘search_location’] = get_query_var( ‘search_location’ ); } } add_action( … Read more