-
-
Save About2git/9bf426bfaa00b5c82ff8 to your computer and use it in GitHub Desktop.
Populate text area on single Posts with Post content in Genesis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_action( 'wp_enqueue_scripts', 'sk_enqueue_script_on_posts' ); | |
| function sk_enqueue_script_on_posts() { | |
| /** | |
| * Load a js file on Post pages and localize it with Post's data | |
| * | |
| * Context: Single Post pages | |
| * | |
| * @author Sridhar Katakam | |
| * @link http://sridharkatakam.com/ | |
| */ | |
| if ( ! is_singular( 'post' ) ) { | |
| return; | |
| } | |
| wp_enqueue_script( 'single-posts', get_stylesheet_directory_uri() . '/js/single-posts.js', array( 'jquery' ), '1.0.0', true ); | |
| /* Get the post title */ | |
| $post_title = get_post_field( 'post_title', $post_id ); | |
| /* Get the raw post content */ | |
| $post_content = get_post_field( 'post_content', $post_id, 'raw' ); | |
| /* Get the Post's URL */ | |
| $post_url = get_permalink(); | |
| $entry_html = '<h1>' . $post_title . '</h1><div>' . $post_content . '<p>Originally published at <a href="' . $post_url . '">' . $post_url . '</a></p></div>'; | |
| wp_localize_script( 'single-posts', 'EntryHTML', array( 'entry_html' => $entry_html ) ); | |
| } | |
| add_action( 'genesis_entry_footer', 'sk_copy_source' ); | |
| /** | |
| * Display a textarea containing the current entry's HTML source | |
| * | |
| * Context: Single Post pages | |
| * | |
| */ | |
| function sk_copy_source() { | |
| if ( ! is_singular( 'post' ) ) { | |
| return; | |
| } ?> | |
| <div class="entry-html-box"> | |
| <p>Want this free content on your website or in a newsletter? Below is the html version so you can copy and paste with ease.</p> | |
| <textarea id="entry-html"></textarea> | |
| </div> | |
| <?php } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jQuery(function( $ ){ | |
| $("textarea#entry-html").text(EntryHTML.entry_html); | |
| $('textarea#entry-html').focus(function() { | |
| var $this = $(this); | |
| $this.select(); | |
| window.setTimeout(function() { | |
| $this.select(); | |
| }, 1); | |
| // Work around WebKit's little problem | |
| function mouseUpHandler() { | |
| // Prevent further mouseup intervention | |
| $this.off("mouseup", mouseUpHandler); | |
| return false; | |
| } | |
| $this.mouseup(mouseUpHandler); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Textarea containing the current entry's HTML source */ | |
| .entry-html-box { | |
| margin-top: 40px; | |
| border-top: 1px dotted #333; | |
| padding-top: 30px; | |
| } | |
| #entry-html { | |
| height: 100px; | |
| color: #333; | |
| font: 12px "Courier New", Courier, mono; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment