WordPress.org

Ready to get started?Download WordPress

Forums

JM Twitter Cards
[resolved] Disable Twitter cards on one page (4 posts)

  1. wellstudio
    Member
    Posted 10 months ago #

    Hi,

    I have one page that dynamically loads content from another database through some GET variables. This means that JM twitter cards is coming up with empty data for the page. I'd like to add my own twitter card info in the page head with a wp_head hook.
    I know how to do all of that, the only problem is that I cannot disable JM twitter cards for this page. I will have a look at the hooks in wordpress, but is there an easy way (say a tick box) that i can disable JM twitter cards for one page?

    Thanks,

    Dan

    http://wordpress.org/plugins/jm-twitter-cards/

  2. wellstudio
    Member
    Posted 10 months ago #

    Hi, I've worked this out for myself -
    There is a function in the plugin called 'add_twitter_card_info', which is added into wp_head.
    You have to use a remove action hook to get rid of it.
    This is the code I used to remove -
    remove_action('wp_head', 'add_twitter_card_info', 99);
    You can drop this into a theme template file before you call get_header(); to remove twitter cards from that page.
    Also, you must give it a priority of 99 (third argument) as it has to match the priority of the original add_action hook.
    Just dropping this in here incase anyone else needs the info.

  3. jmlapam
    Member
    Plugin Author

    Posted 10 months ago #

    while it might work I would not recommand to proceed this way. You'd better target pages in the functions.php or in a functionality plugin :

    add_action('wp_head','disable_twitter_card_info');
    function disable_twitter_card_info() {
    	if(is_page(array(19,'contact',21))) remove_action('wp_head', 'add_twitter_card_info',99);
    }
  4. wellstudio
    Member
    Posted 10 months ago #

    That's true.
    In this case it was for a custom page that pulled details from a database based on some GET variables, so it was fine just to build it into that page template.
    But always good to put things in functions.php!

Reply

You must log in to post.

About this Plugin

About this Topic