Plugin Directory

Changeset 2261567


Ignore:
Timestamp:
03/16/2020 07:16:03 AM (6 years ago)
Author:
manojsv
Message:

Update 1.1

Location:
ams-hide-page-and-post-title
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ams-hide-page-and-post-title/tags/1.0/ams-hide-page-and-post-title.php

    r1523538 r2261567  
    44Description: Allows authors to hide the title tag on single pages and posts via the edit post screen.
    55Author: Manoj Sathyavrathan
    6 Version: 1.0
     6Version: 1.1
    77Text Domain: msv-ams-hide-page-and-post-title
    88*/
     
    4747        add_action( 'delete_post', array( $this, 'ams_delete_post_action' ) );
    4848       
    49         if( ! is_admin() ) {
    50             add_filter( 'the_title', array($this, 'ams_the_title') );
    51         }
     49        add_filter( 'the_title', array($this, 'ams_wpse309151_title_update'), 10, 2 );
     50        add_filter( 'pre_wp_nav_menu', array($this, 'ams_wpse309151_remove_title_filter_nav_menu'), 10, 2 );
     51        add_filter( 'wp_nav_menu_items', array($this, 'ams_wpse309151_add_title_filter_non_menu'), 10, 2 );
    5252    } // hooks()
    5353   
     
    103103    } // on_delete()
    104104   
    105     function ams_the_title( $title ) {
    106         global $post;
    107         $value = get_post_meta( $post->ID, $this->ams_term, true );
    108        
    109         if ( 'on' == $value )
    110             return $title = '';
    111 
     105        // Hide post & page title
     106    function ams_wpse309151_title_update( $title, $post_id ) {
     107        $post_type = get_post_type( $post_id );
     108        $value = get_post_meta( $post_id, $this->ams_term, true );
     109        if( !is_admin() && ( $post_type === 'post' || $post_type === 'page' ) ) {
     110           
     111            if ( 'on' == $value ){
     112                $title = '';
     113                return $title;
     114            }
     115            //return $title;
     116        }
    112117        return $title;
    113118    }
     119   
     120
     121    function ams_wpse309151_remove_title_filter_nav_menu( $nav_menu, $args ) {
     122        // we are working with menu, so remove the title filter
     123        remove_filter( 'the_title', array($this, 'ams_wpse309151_title_update'), 10, 2 );
     124        return $nav_menu;
     125    }
     126    // this filter fires just before the nav menu item creation process
     127   
     128
     129    function ams_wpse309151_add_title_filter_non_menu( $items, $args ) {
     130        // we are done working with menu, so add the title filter back
     131        add_filter( 'the_title', array($this, 'ams_wpse309151_title_update'), 10, 2 );
     132        return $items;
     133    }
     134    // this filter fires after nav menu item creation is done
     135   
    114136   
    115137}
  • ams-hide-page-and-post-title/tags/1.0/readme.txt

    r2261261 r2261567  
    55Donate link: https://www.paypal.me/manojsv
    66Tested up to: 5.3.2
    7 Stable tag: 1.0
     7Stable tag: 1.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3939
    4040== Changelog ==
    41 
     41= Version 1.1 =
     42* Fixed issue with menu
    4243= Version 1.0 =
    4344* First Release
  • ams-hide-page-and-post-title/trunk/ams-hide-page-and-post-title.php

    r1523538 r2261567  
    44Description: Allows authors to hide the title tag on single pages and posts via the edit post screen.
    55Author: Manoj Sathyavrathan
    6 Version: 1.0
     6Version: 1.1
    77Text Domain: msv-ams-hide-page-and-post-title
    88*/
     
    4747        add_action( 'delete_post', array( $this, 'ams_delete_post_action' ) );
    4848       
    49         if( ! is_admin() ) {
    50             add_filter( 'the_title', array($this, 'ams_the_title') );
    51         }
     49        add_filter( 'the_title', array($this, 'ams_wpse309151_title_update'), 10, 2 );
     50        add_filter( 'pre_wp_nav_menu', array($this, 'ams_wpse309151_remove_title_filter_nav_menu'), 10, 2 );
     51        add_filter( 'wp_nav_menu_items', array($this, 'ams_wpse309151_add_title_filter_non_menu'), 10, 2 );
    5252    } // hooks()
    5353   
     
    103103    } // on_delete()
    104104   
    105     function ams_the_title( $title ) {
    106         global $post;
    107         $value = get_post_meta( $post->ID, $this->ams_term, true );
    108        
    109         if ( 'on' == $value )
    110             return $title = '';
    111 
     105        // Hide post & page title
     106    function ams_wpse309151_title_update( $title, $post_id ) {
     107        $post_type = get_post_type( $post_id );
     108        $value = get_post_meta( $post_id, $this->ams_term, true );
     109        if( !is_admin() && ( $post_type === 'post' || $post_type === 'page' ) ) {
     110           
     111            if ( 'on' == $value ){
     112                $title = '';
     113                return $title;
     114            }
     115            //return $title;
     116        }
    112117        return $title;
    113118    }
     119   
     120
     121    function ams_wpse309151_remove_title_filter_nav_menu( $nav_menu, $args ) {
     122        // we are working with menu, so remove the title filter
     123        remove_filter( 'the_title', array($this, 'ams_wpse309151_title_update'), 10, 2 );
     124        return $nav_menu;
     125    }
     126    // this filter fires just before the nav menu item creation process
     127   
     128
     129    function ams_wpse309151_add_title_filter_non_menu( $items, $args ) {
     130        // we are done working with menu, so add the title filter back
     131        add_filter( 'the_title', array($this, 'ams_wpse309151_title_update'), 10, 2 );
     132        return $items;
     133    }
     134    // this filter fires after nav menu item creation is done
     135   
    114136   
    115137}
  • ams-hide-page-and-post-title/trunk/readme.txt

    r2261261 r2261567  
    55Donate link: https://www.paypal.me/manojsv
    66Tested up to: 5.3.2
    7 Stable tag: 1.0
     7Stable tag: 1.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3939
    4040== Changelog ==
    41 
     41= Version 1.1 =
     42* Fixed issue with menu
    4243= Version 1.0 =
    4344* First Release
Note: See TracChangeset for help on using the changeset viewer.