How to get post URL in the_content filter?

You can do a conditional and return the post’s URL by using a get_the_permalink() in conjunction with is_single(): add_filter( ‘the_content’, ‘my_filter’ ); function my_filter( $content ) { // Check if we’re inside the main loop in a single post page. if ( is_single() && in_the_loop() && is_main_query() ) { return $content . get_the_permalink(); } return … Read more

Can wp_localize_script be used within a shortcode?

Default parameters for wp_enqueue_script will output the script in the wp_head function. Shortcodes typically execute later, when main content is being output. In that case, calling wp_localize_script in the Shortcode handler will have no effect, because the script has already been output. Setting the $in_footer parameter to true when enqueueing the script will delay script … Read more

Plugin exceeds memory limit

The code you use also uses WordPress functions that will first load posts (and other relevant data) in memory first and cache them using object cache. So, to delete 100.000 posts, your code will try to load each post in memory and that can take a lot of memory. I am not sure how high … Read more

redirect on theme switch – WordPress

You could use the after_theme_switch hook to do this, and wp_safe_redirect() works fine to redirect to local urls only. In your callback function check for the $_GET[‘activated’] flag or you may get a “too many redirects” type of error. add_action( ‘after_switch_theme’, ‘my_theme_redirect’ ); function my_theme_redirect() { if( isset( $_GET[‘activated’] ) ) { wp_safe_redirect( admin_url(‘admin.php?page=alecaddd_sunset’) ); … Read more