How to remove Nextpage tag inside posts text depending of utm_campaign

You can use the_post hook to remove <!–nextpage–>. In this case: add_action( ‘the_post’, ‘campaign_remove_nextpage’, 99); function campaign_remove_nextpage ( $post ) { if ( ($_GET[‘utm_campaign’]== ‘nonextpagecampaign’) && (false !== strpos( $post->post_content, ‘<!–nextpage–>’ )) ) { // Reset the global $pages: $GLOBALS[‘pages’] = [ $post->post_content ]; // Reset the global $numpages: $GLOBALS[‘numpages’] = 0; // Reset the … Read more

Strategy for handling hierarchical pages with empty parent content

I am using two strategies here… 1) is simple redirection to first child (using menu order) page-redirect.php <?php /* * Template Name: Redirector * Description: Empty Holder (redirect page) */ $rp = new WP_Query(array( ‘post_parent’ => get_the_id(), ‘post_type’ => ‘page’, ‘order’ => ‘asc’, ‘orderby’ => ‘menu_order’ )); if ($rp->have_posts()) while ( $rp->have_posts() ) { $rp->the_post(); … Read more

How to move wp-content (or uploads) outside of the WordPress directory

You have to define WP_CONTENT_DIR and WP_CONTENT_URL: const WP_CONTENT_DIR = ‘/path/to/new/directory’; const WP_CONTENT_URL = ‘http://content.wp’; The new path must be accessible for read and write operation from the WordPress core directory. You might need a helper function to add the new directory path to the open_basedir list: /** * Add a new directory to the … Read more

Get entire page content (generated HTML in browser)

You can use output buffering to accomplish this. Add a high priority hook directly before the template is rendered: add_action(‘template_redirect’, ‘foo_buffer_go’, 0); function foo_buffer_go(){ ob_start(‘foo_buffer_callback’); } Add a shutdown hook with an extremely low priority. add_action(‘shutdown’, ‘foo_buffer_stop’, 1000); function foo_buffer_stop(){ ob_end_flush(); } Inside your callback, you manipulate the rendered HTML. function foo_buffer_callback($buffer){ //Do something with … Read more

Extract image from content and set it as the featured image

Why not utilize two hooks, one before post saved and one after post saved? content_save_pre : Function attached with this hook will remove image from content and store it in session/transient. save_post : With this hook you will have id of post. Function attached with this hook will set featured image for the post with … Read more