最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to add a link of “one” website in posts of “second” website in multisite Wordpress

programmeradmin1浏览0评论

I want to display the One website url in other site posts and visa versa. So I am trying to use switch_to_blog() but not able to get the other webite url in the concept of multisite in Wordpress.

I want to display the One website url in other site posts and visa versa. So I am trying to use switch_to_blog() but not able to get the other webite url in the concept of multisite in Wordpress.

Share Improve this question asked Sep 22, 2019 at 11:38 Akshay JainAkshay Jain 1033 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

if you want to display the One website url in other site's posts at bottom. you can use below code. it will display all other site links excepts current site of multisite at end of post content of "post" post type. you can change post type as your need.

    add_filter('the_content','add_site_url_in_bottom',10,1);
    function add_site_url_in_bottom($content)
    {
         global $post;
         if ($post->post_type == 'post') {  

             if ( function_exists( 'get_sites' ) && class_exists( 'WP_Site_Query' ) ) {
               $args = array(
                   "site__not_in" => get_current_blog_id(), 
               );
               $sites = get_sites($args);
               $content .= '<h3>Other Site URLS</h3>';

               foreach ( $sites as $site ) {
                   switch_to_blog( $site->blog_id );
                   $content .= 'site url : <a href="'.get_site_url($site->blog_id).'">';
                   $content .=  get_bloginfo( 'name' );
                   $content .= '</a><br>';
                   restore_current_blog();  
              }
          }
       }
      return $content;
   }

see https://prnt.sc/p9pr4z for reference.

发布评论

评论列表(0)

  1. 暂无评论