Hide Title - Version 1.0.1

Version Description

  • Changed the jQuery to use a less brute force method of hiding the title.
  • Added a set_selector() method to allow end-users to specify the css selector to hide.

=

Download this release

Release Info

Developer kraftbj
Plugin Icon wp plugin Hide Title
Version 1.0.1
Comparing to
See all releases

Version 1.0.1

Files changed (3) hide show
  1. dojo-digital-hide-title.php +179 -0
  2. readme.txt +64 -0
  3. uninstall.php +5 -0
dojo-digital-hide-title.php ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Hide Title
4
+ Plugin URI: http://dojodigital.com
5
+ Description: Allows authors to hide the title tag on single pages and posts via the edit post screen.
6
+ Version: 1.0.1
7
+ Author: Randall Runnels
8
+ Author URI: http://dojodigital.com
9
+ */
10
+
11
+ if ( !class_exists( 'DojoDigitalHideTitle' ) ) {
12
+
13
+ class DojoDigitalHideTitle {
14
+
15
+ private $slug = 'dojodigital_toggle_title';
16
+ private $selector = '.entry-title';
17
+
18
+ /**
19
+ * PHP 4 Compatible Constructor
20
+ */
21
+ function DojoDigitalHideTitle(){ $this->__construct(); }
22
+
23
+ /**
24
+ * PHP 5 Constructor
25
+ */
26
+ function __construct(){
27
+
28
+ add_action( 'add_meta_boxes', array( $this, 'add_box' ) );
29
+ add_action( 'save_post', array( $this, 'on_save' ) );
30
+ add_action( 'delete_post', array( $this, 'on_delete' ) );
31
+ add_action( 'wp_head', array( $this, 'head_insert' ) );
32
+ add_action( 'the_title', array( $this, 'wrap_title' ) );
33
+ add_action( 'wp_enqueue_scripts', array( $this, 'load_scripts' ) );
34
+
35
+ } // __construct()
36
+
37
+
38
+ private function is_hidden( ){
39
+
40
+ if( is_singular() ){
41
+
42
+ global $post;
43
+
44
+ $toggle = get_post_meta( $post->ID, $this->slug, true );
45
+
46
+ if( (bool) $toggle ){
47
+ return true;
48
+ } else {
49
+ return false;
50
+ }
51
+
52
+ } else {
53
+ return false;
54
+ }
55
+
56
+ } // is_hidden()
57
+
58
+
59
+ public function head_insert(){
60
+
61
+ if( $this->is_hidden() ){ ?>
62
+ <!-- Dojo Digital Hide Title -->
63
+ <script type="text/javascript">
64
+ jQuery(document).ready(function($){
65
+ if( $('<?php echo $this->selector; ?>').length != 0 ){
66
+ $('<?php echo $this->selector; ?> span.<?php echo $this->slug; ?>').parents('<?php echo $this->selector; ?>:first').hide();
67
+ } else {
68
+ $('h1 span.<?php echo $this->slug; ?>').parents('h1:first').hide();
69
+ $('h2 span.<?php echo $this->slug; ?>').parents('h2:first').hide();
70
+ }
71
+
72
+ });
73
+ </script>
74
+ <noscript><style type="text/css"> <?php echo $this->selector; ?> { display:none !important; }</style></noscript>
75
+ <!-- END Dojo Digital Hide Title -->
76
+
77
+ <?php }
78
+
79
+ } // head_insert()
80
+
81
+
82
+ public function add_box(){
83
+
84
+ $posttypes = array( 'post', 'page' );
85
+
86
+ foreach ( $posttypes as $posttype ){
87
+ add_meta_box( $this->slug, 'Hide Title', array( $this, 'build_box' ), $posttype, 'side' );
88
+ }
89
+
90
+ } // add_box()
91
+
92
+
93
+ public function build_box( $post ){
94
+
95
+ $value = get_post_meta( $post->ID, $this->slug, true );
96
+
97
+ $checked = '';
98
+
99
+ if( (bool) $value ){ $checked = ' checked="checked"'; }
100
+
101
+ wp_nonce_field( $this->slug . '_dononce', $this->slug . '_noncename' );
102
+
103
+ ?>
104
+ <label><input type="checkbox" name="<?php echo $this->slug; ?>" <?php echo $checked; ?> /> Hide the title on singular page views.</label>
105
+ <?php
106
+
107
+ } // build_box()
108
+
109
+
110
+ public function wrap_title( $content ){
111
+
112
+ if( $this->is_hidden() ){
113
+ $content = '<span class="' . $this->slug . '">' . $content . '</span>';
114
+ }
115
+
116
+ return $content;
117
+
118
+ } // wrap_title()
119
+
120
+
121
+ public function load_scripts(){
122
+
123
+ if( $this->is_hidden() ){ wp_enqueue_script( 'jquery' ); }
124
+
125
+ } // load_scripts()
126
+
127
+
128
+ public function on_save( $postID ){
129
+
130
+ if ( ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
131
+ || !isset( $_POST[ $this->slug . '_noncename' ] )
132
+ || !wp_verify_nonce( $_POST[ $this->slug . '_noncename' ], $this->slug . '_dononce' ) ) {
133
+ return $postID;
134
+ }
135
+
136
+ $old = get_post_meta( $postID, $this->slug, true );
137
+ if( isset( $_POST[ $this->slug ] ) ){
138
+ $new = $_POST[ $this->slug ];
139
+ } else {
140
+ $new = null;
141
+ }
142
+
143
+ if( $old ){
144
+ if ( is_null( $new ) ){
145
+ delete_post_meta( $postID, $this->slug );
146
+ } else {
147
+ update_post_meta( $postID, $this->slug, $new, $old );
148
+ }
149
+ } elseif ( !is_null( $new ) ){
150
+ add_post_meta( $postID, $this->slug, $new );
151
+ }
152
+
153
+ return $postID;
154
+
155
+ } // on_save()
156
+
157
+
158
+ public function on_delete( $postID ){
159
+ delete_post_meta( $postID, $this->slug );
160
+ return $postID;
161
+ } // on_delete()
162
+
163
+
164
+ public function set_selector( $selector ){
165
+
166
+ if( isset( $selector ) && is_string( $selector ) ){
167
+ $this->selector = $selector;
168
+ }
169
+
170
+ } // set_selector()
171
+
172
+
173
+ } // DojoDigitalHideTitle
174
+
175
+ $DojoDigitalHideTitle = new DojoDigitalHideTitle();
176
+
177
+ } // !class_exists( 'DojoDigitalHideTitle' )
178
+
179
+ ?>
readme.txt ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Hide Title ===
2
+
3
+ Contributors: dojodigital
4
+ Plugin Name: Hide Title
5
+ Plugin URI: http://dojodigital.com/developer-tools/hide-title/
6
+ Tags: wp, title
7
+ Author URI: http://dojodigital.com/
8
+ Author: Dojo Digital
9
+ Requires at least: 3.0
10
+ Tested up to: 3.4.1
11
+ Stable tag: 1.0.1
12
+ Version: 1.0.1
13
+
14
+ Allows authors to hide the title on single pages and posts via the edit post screen.
15
+
16
+ == Description ==
17
+
18
+ This plugin allows the author of a post or page to hide the title and it's containing HTML element from the single view ( is_singular() ).
19
+
20
+ == Installation ==
21
+
22
+ 1. Upload the `hide-title` folder to the `/wp-content/plugins/` directory
23
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
24
+
25
+ == Screenshots ==
26
+
27
+ 1. This Meta Box will be added to the Edit screen for pages & posts
28
+
29
+ == Changelog ==
30
+
31
+ = 1.0.1 =
32
+
33
+ * Changed the jQuery to use a less brute force method of hiding the title.
34
+ * Added a set_selector() method to allow end-users to specify the css selector to hide.
35
+
36
+ == Upgrade Notice ==
37
+
38
+ = 1.0.1 =
39
+
40
+ * This version uses a less brute force method of hiding the title by trying to find and hide `.entry-title` before looking for the title inside of `h1` or `h2` tags and hiding them. This version also adds a method for theme editors to change the selector from the default `.entry-title` to whatever they want to use.
41
+
42
+ == Frequently Asked Questions ==
43
+
44
+ = Hey! This plugin is hiding things I don't want hidden! =
45
+
46
+ By default this plugin looks for the `.entry-title` class and hides it. If it doesn't find it it will look for any `h1` or `h2` elements that contain the title and hide them instead. To change the default `.entry-title` selector to something that makes more sense to you, add the following code to the functions.php file of your current theme:
47
+
48
+ `global $DojoDigitalHideTitle;
49
+ if ( isset( $DojoDigitalHideTitle ) ){
50
+ // Be sure to replace ".your-selector" with your selector!
51
+ $DojoDigitalHideTitle->set_selector('.entry-title');
52
+ }`
53
+
54
+ As noted in the comments, you'll need to replace the string `.your-selector` with the css selector you'd like hidden. It can be any valid css selector such as `h1`, `.myclass`, `#myid`, etc. I recommend using a class or id to avoid accidentally hiding unforeseen elements.
55
+
56
+ = I don't want to edit my theme files, can't you just add an option page? =
57
+
58
+ I could, but I'd like to avoid adding Yet Another Options Page if I can. If enough people request it though, I'll go ahead and bite the bullet.
59
+
60
+
61
+
62
+
63
+
64
+
uninstall.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ global $wpdb;
4
+
5
+ $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->postmeta . ' WHERE meta_key="dojodigital_toggle_title"' ) );