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

Is there un-wp_autop function?

I just ran into this situation. Here is a function I used to undo wpautop. I might be missing something, but this is a good start: function reverse_wpautop($s) { //remove any new lines already in there $s = str_replace(“\n”, “”, $s); //remove all <p> $s = str_replace(“<p>”, “”, $s); //replace <br /> with \n $s … Read more

Editing Complex Pages in Visual Mode

One thing you could do is create page templates for complex pages and simply add the content through the editor, leave as little mark-up as possible in the editor. Another thing that might help is using the editor style (activated with add_editor_style() in functions.php) and defined in editor-style.css so the client has a better sense … 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

How to Handle Distributed Development Workflow

Caution: very mac/linux/unix centric thoughts ahead. Includes a lot of command line fu. Put All the Code Under Version Control I like git. Mark Jaquith has some good suggestions on keeping an entire site under version control using git and submodules for the WordPress core. You could also put plugins in as git submodules. The … Read more