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 do I use Shortcodes inside of HTML tags?

Hope this helps someone: Instead of doing this: <a href=”https://example.com/folder/edit.php?action=someaction&id=[foocode parameter=”value”]&edittoken=[foocode parameter=”othervalue”]”>linktext</a> You can do this: [foocode parameter1=value parameter2=othervalue] and then do this: add_shortcode( ‘foocode’, ‘prefix_foocode’ ); function prefix_foocode( $atts ) { // Normalize $atts, set defaults and do whatever you want with $atts. $html=”<a href=”https://example.com/folder/edit.php?action=someaction&id=” . $atts[‘parameter1′] .’&edittoken=’ . $atts[‘parameter2’] . ‘”>linktext</a>’; return $html; … Read more

Modify previous and next text from pagination links

I found out a way that you can place any text. You just need to create an array where you want the paginate_links to appear. <!– Put this in your functions.php –> <?php $args = array( ‘base’ => ‘%_%’, ‘format’ => ‘?paged=%#%’, ‘total’ => 1, ‘current’ => 0, ‘show_all’ => false, ‘end_size’ => 1, ‘mid_size’ … Read more

wp_editor adds HTML entities to the content

WordPress is running addslashes on POST input. The value you get from the data base looks probably like: <img title=\”\” … … and the editor tries to enforce valid markup from that. So … call the editor with … wp_editor( stripslashes( $content ), strtolower($value[‘id’]), $settings );

Why do templates contain so many PHP tag pairs?

As always, people copy paste whatever they learned from and IIRC the first style is the coding style of wordpress core. As you said yourself, when there is a big block of generated HTML it is easier to look at (and balance tags) under the first style, but pragmatic people will use the second whenever … Read more

How to get the custom header image’s alt text?

/** * Get custom header’s alt data. * * @link http://wordpress.stackexchange.com/q/151850/1685 * * @return string */ function wpse_151850_get_header_image_alt() { $attachment_id = 0; if ( is_random_header_image() && $header_url = get_header_image() ) { // For a random header, we have to search for a match against all headers. foreach ( get_uploaded_header_images() as $header ) { if ( … Read more