WordPress.org

Forums

WordPress SEO News
Custom post types not supported? (6 posts)

  1. biznit
    Member
    Posted 2 years ago #

    This plugin (WordPress SEO News from Yoast) doesn't seem to recognize custom post types, unless I'm doing something improperly.

    It's weird because on the Google News Sitemaps settings page, it lists all of our custom post types with tickboxes under the heading "Post Types to include in News Sitemap", which would seem to indicate that it's aware of custom post types and is set up to include them.

    But only "posts" are included in the xml news sitemap, and on individual post pages, in the "WordPress SEO by Yoast" box, the "Google News" tab does not show up if it's a custom post type.

    I hope that makes sense, and thanks in advance for any responses.

    http://wordpress.org/extend/plugins/wordpress-seo-news/

  2. ronaldblk
    Member
    Posted 2 years ago #

    It does make sense, i've got the same issue. Sitemap is created but empty although I enabled custom post types

  3. Sarah F
    Member
    Posted 2 years ago #

    same with me, everything gets aded except for custom post types

  4. bleggate
    Member
    Posted 1 year ago #

    Hi Guys check out this link where there is a solution that partially works for me but works for others. https://github.com/jdevalk/Google-News-Sitemap/issues/20

    I think it depends on how your custom posts are set up? Open to your solution on how to make this work 100%

  5. bleggate
    Member
    Posted 1 year ago #

    This code works on the Github page for me now. What you have to be sure of is to change the code on line 58

    from

    $post_types = "'post'";

    to

    $post_types = "'post', 'tribe_events'";

    with the name of your custom posts being in my case 'tribe_events, the name has to be exactly what your custom posts are called.

    I hope this helps.

  6. bleggate
    Member
    Posted 1 year ago #

    Sorry an update on this, follow the `code changes below :)

    Look for xml-news-metabox.php and replace entire file with the following code, I changed how script checks for posts that are checked in the settings and displays nothing if its not included.

    ----------------

    <?php

    /**
    * This code handles the display of the Google news tab in the WP SEO metabox.
    */
    class WPSEO_XML_News_Sitemap_Metabox extends WPSEO_Metabox {

    /**
    * Options array
    */
    private $options = array();

    /**
    * Class constructor
    */
    public function __construct() {
    $this->options = get_option( 'wpseo_news' );
    add_filter( 'wpseo_save_metaboxes', array( &$this, 'save_meta_boxes' ), 10, 1 );
    add_action( 'wpseo_tab_header', array( &$this, 'tab_header' ) );
    add_action( 'wpseo_tab_content', array( &$this, 'tab_content' ) );
    }

    /**
    * Ping Google about the update of this sitemap
    */
    public function ping() {
    // Ping Google. Just do it. Not optional because if you don't want to ping Google you don't need no freaking news sitemap.
    wp_remote_get( 'http://www.google.com/webmasters/tools/ping?sitemap=' . home_url( 'news-sitemap.xml' ) );
    }

    /**
    * Make sure the parent class knows which meta_boxes content to save.
    *
    * @param array $mbs meta boxes that need to be saved.
    * @return array
    */
    public function save_meta_boxes( $mbs ) {
    $mbs = array_merge( $mbs, $this->get_meta_boxes() );
    return $mbs;
    }

    /**
    * Display the tab header in the WP SEO metabox
    */
    public function tab_header() {
    global $post;

    if($this->options['newssitemap_include_'.$post->post_type] == "on"){
    echo '<li class="news"><a href="#wpseo_news">' . __( 'Google News' ) . '</a>';
    } else {
    return false;
    }
    }

    /**
    * Create the content for the tab and return it to the parent class for handling.
    *
    * @return string Contents of the tab
    */
    public function tab_content() {
    global $post;

    if($this->options['newssitemap_include_'.$post->post_type] == "on"){
    $content = '';
    foreach ( $this->get_meta_boxes() as $meta_box ) {
    $content .= $this->do_meta_box( $meta_box );
    }
    $this->do_tab( 'news', __( 'Google News' ), $content );
    } else {
    return false;
    }
    }

    /**
    * The metaboxes to display and save for the tab
    *
    * @return array $mbs
    */
    public function get_meta_boxes() {
    $mbs = array();
    $stdgenre = ( isset( $this->options['newssitemap_default_genre'] ) ) ? $this->options['newssitemap_default_genre'] : 'blog';
    $mbs['newssitemap-include'] = array(
    "name" => "newssitemap-include",
    "type" => "checkbox",
    "std" => "on",
    "title" => __( "Include in News Sitemap" )
    );
    $mbs['newssitemap-keywords'] = array(
    "name" => "newssitemap-keywords",
    "type" => "text",
    "std" => "",
    "title" => __( "Meta News Keywords" ),
    "description" => __( "Comma separated list of the keywords this article aims at.", "wordpress-seo" ),
    );
    $mbs['newssitemap-genre'] = array(
    "name" => "newssitemap-genre",
    "type" => "multiselect",
    "std" => $stdgenre,
    "title" => __( "Google News Genre", 'yoast-wpseo' ),
    "description" => __( "Genre to show in Google News Sitemap.", 'yoast-wpseo' ),
    "options" => array(
    "none" => __( "None", 'yoast-wpseo' ),
    "pressrelease" => __( "Press Release", 'yoast-wpseo' ),
    "satire" => __( "Satire", 'yoast-wpseo' ),
    "blog" => __( "Blog", 'yoast-wpseo' ),
    "oped" => __( "Op-Ed", 'yoast-wpseo' ),
    "opinion" => __( "Opinion", 'yoast-wpseo' ),
    "usergenerated" => __( "User Generated", 'yoast-wpseo' ),
    ),
    );
    $mbs['newssitemap-original'] = array(
    "name" => "newssitemap-original",
    "std" => "",
    "type" => "text",
    "title" => __( "Original Source", 'yoast-wpseo' ),
    "description" => __( 'Is this article the original source of this news? If not, please enter the URL of the original source here. If there are multiple sources, please separate them by a pipe symbol: | .', 'yoast-wpseo' ),
    );
    $mbs['newssitemap-stocktickers'] = array(
    "name" => "newssitemap-stocktickers",
    "std" => "",
    "type" => "text",
    "title" => __( "Stock Tickers", 'yoast-wpseo' ),
    "description" => __( 'A comma-separated list of up to 5 stock tickers of the companies, mutual funds, or other financial entities that are the main subject of the article. Each ticker must be prefixed by the name of its stock exchange, and must match its entry in Google Finance. For example, "NASDAQ:AMAT" (but not "NASD:AMAT"), or "BOM:500325" (but not "BOM:RIL").', 'yoast-wpseo' ),
    );
    return $mbs;
    }

    }

    $wpseo_news_xml_metabox = new WPSEO_XML_News_Sitemap_Metabox();

    ---------------------
    `
    then change the following code in xml-news-sitemap-class.php line 58 from:

    $post_types = "'post'";

    to

    $post_types = "'post', 'tribe_events'";

    with the name of your custom posts being in my case 'tribe_events, the name has to be exactly what your custom posts are called.

    Thanks

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.