Support other SEO plugins
-
Hi Walter,
it would be nice to have the option to use other SEO plugins.
I’ll leave my solution for the community, maybe it’s the easier way to fully customize the template being served.<?php /** * Plugin Name: MyLinks Custom Template * Description: Copy the original template from MyLinks plugin and put it in the same folder as this custom plugin, call it "template.php". ORIGINAL TEMPLATE: wp-content/plugins/wp-mylinks/public/partials/wp-mylinks-base-template.php */ # Remove the original filter remove_filter('single_template', 'wp_mylinks_template'); # Add our custom filter and template add_filter('single_template', function($single) { global $post; $myplugin = plugin_dir_path( __FILE__ ) . 'template.php'; if ($post->post_type == 'mylink') { if (file_exists($myplugin)) { return $myplugin; } } return $single; });
Thanks again for this fine plugin ????
Viewing 1 replies (of 1 total)
-
Here’s the template.php I ended up writing, I cleaned and simplified the original one, adding OpenGraph meta tags:
<?php /** * Custom template for the MyLinks page. */ function g_meta($item){ return get_post_meta( get_the_ID(), mylinks_prefix($item), true ); } function g_social($social, $icon, $def_icon){ if(empty($social)) return; printf( '<a href="%s" target="_blank" class="user-profile-link" rel="noopener noreferrer nofollow">', esc_html( $social ) ); if ( empty( $icon ) ) printf( '<img align="middle" class="mylinks-social-icons" width="32" height="32" src="%s">', esc_url( plugins_url( "/wp-mylinks/public/images/{$def_icon}" ) ) ); else printf( '<img align="middle" class="mylinks-social-icons" width="32" height="32" src="%s">', esc_html( $icon ) ); echo '</a>'; } $avatar = g_meta('avatar'); $name = g_meta('name'); $description = g_meta('description'); # Check The SEO Framework names: https://github.com/sybrew/the-seo-framework/issues/169 $seo_title = get_post_meta($post->ID, '_genesis_title', true ); $my_title = g_meta('meta-title'); if (!empty($seo_title)) $meta_title = $seo_title; elseif (!empty($my_title)) $meta_title = $my_title; else $meta_title = get_option(sanitize_text_field('mylinks_meta_title')); $seo_desc = get_post_meta($post->ID, '_genesis_description', true ); $my_desc = g_meta('meta-description'); if (!empty($seo_desc)) $meta_description = $seo_desc; elseif (!empty($my_desc)) $meta_description = $my_desc; else $meta_description = get_option(sanitize_text_field('mylinks_meta_description')); $seo_url = get_post_meta($post->ID, '_genesis_canonical_url', true ); if (!empty($seo_url)) $meta_canonical = $seo_url; else $meta_canonical = get_permalink(); $seo_img = get_post_meta($post->ID, '_social_image_url', true ); if (!empty($seo_img)) $meta_image = $seo_img; else $meta_image = $avatar; $meta_sitename = get_bloginfo( 'name' ); $seo_noindex = get_post_meta($post->ID, '_genesis_noindex', true ); $my_post_noindex = g_meta('noindex'); $my_site_noindex = get_option(sanitize_text_field('wp_mylinks_noindex')); if (!empty($seo_noindex)) $set_noindex = $seo_noindex; elseif(!empty($my_post_noindex)) $set_noindex = $my_post_noindex; else $set_noindex = $my_site_noindex; $seo_nofollow = get_post_meta($post->ID, '_genesis_nofollow', true ); $my_post_nofollow = g_meta('nofollow'); $my_site_nofollow = get_option(sanitize_text_field('wp_mylinks_nofollow')); if (!empty($seo_nofollow)) $set_nofollow = $seo_nofollow; elseif(!empty($my_post_nofollow)) $set_nofollow = $my_post_nofollow; else $set_nofollow = $my_site_nofollow; $noindex = $set_noindex === "yes" ? "noindex" : "index"; $nofollow = $set_nofollow === "yes" ? "nofollow" : "follow"; $analytics_script = get_option(sanitize_text_field('wp_mylinks_analytics')); if ($header_script = g_meta('mylinks-single-custom-header-script')); else $header_script = get_option(sanitize_text_field('wp_mylinks_header_script')); if ($custom_css = g_meta('mylinks-single-custom-styles')); else $custom_css = get_option(sanitize_text_field('wp_mylinks_custom_css')); $theme_value = get_option( 'mylinks_theme' ); $options = wp_mylinks_theme_callback(); $key = g_meta('theme'); $option_name = isset( $options[ $key ] ) ? $options[ $key ] : $options['default']; $facebook_url = g_meta('facebook-url'); $facebook_icon = g_meta('facebook-icon'); $twitter_url = g_meta('twitter-url'); $twitter_icon = g_meta('twitter-icon'); $linkedin_url = g_meta('linkedin-url'); $linkedin_icon = g_meta('linkedin-icon'); $instagram_url = g_meta('instagram-url'); $instagram_icon = g_meta('instagram-icon'); $youtube_url = g_meta('youtube-url'); $youtube_icon = g_meta('youtube-icon'); $pinterest_url = g_meta('pinterest-url'); $pinterest_icon = g_meta('pinterest-icon'); $tiktok_url = g_meta('tiktok-url'); $tiktok_icon = g_meta('tiktok-icon'); $links = g_meta('links'); if ($footer_script = g_meta('mylinks-single-custom-footer-script')); else $footer_script = get_option(sanitize_text_field('wp_mylinks_footer_script')); ?><!DOCTYPE html> <html <?php language_attributes(); ?>> <head> <meta charset="<?php bloginfo( 'charset' ); ?>"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="profile" href="https://gmpg.org/xfn/11"> <link rel="pingback" href="<?php echo esc_url( get_bloginfo( 'pingback_url' ) ); ?>"> <link rel="canonical" href="<?php echo $meta_canonical; ?>" /> <!-- Start Favicon --> <?php $single_favicon = g_meta('single-favicon'); ?> <?php $global_favicon = get_option('mylinks_upload_favicon'); ?> <?php if ( empty( $single_favicon ) ) : ?> <link rel="icon" type="image/png" href="<?php echo esc_html( $global_favicon ); ?>"> <?php else : ?> <link rel="icon" type="image/png" href="<?php echo esc_html( $single_favicon ); ?>"> <?php endif; ?> <!-- End Favicon --> <title><?php echo $meta_title; ?></title> <meta name="description" content="<?php echo $meta_description; ?>"> <meta name="robots" content="<?php echo $noindex ?>, <?php echo $nofollow ?>" /> <meta name="googlebot" content="<?php echo $noindex ?>, <?php echo $nofollow ?>, max-snippet:-1, max-image-preview:large, max-video-preview:-1" /> <meta name="bingbot" content="<?php echo $noindex ?>, <?php echo $nofollow ?>, max-snippet:-1, max-image-preview:large, max-video-preview:-1" /> <meta name="image" content="<?php echo $meta_image; ?>"> <!-- Schema.org for Google --> <meta itemprop="name" content="<?php echo $meta_title; ?>"> <meta itemprop="description" content="<?php echo $meta_description; ?>"> <meta itemprop="image" content="<?php echo $meta_image; ?>"> <!-- Open Graph general (Facebook, Pinterest & Google+) --> <meta name="og:title" content="<?php echo $meta_title; ?>"> <meta name="og:description" content="<?php echo $meta_description; ?>"> <meta name="og:image" content="<?php echo $meta_image; ?>"> <meta name="og:url" content="<?php echo $meta_canonical; ?>"> <meta name="og:site_name" content="<?php echo $meta_sitename; ?>"> <meta name="og:locale" content="pt_BR"> <meta name="og:type" content="website"> <?php wp_enqueue_style('mylinks-public-css'); wp_styles()->do_item('mylinks-public-css'); echo $analytics_script; echo $header_script; if ($custom_css == '') { echo ''; } else { echo '<style type="text/css">'.$custom_css .'</style>'; } ?> </head> <?php printf( '<body class="mylinks-body %s">', 'none' === $key ? $theme_value : $key ); if ( have_posts() ): while ( have_posts() ): the_post(); ?> <div class="mylinks"> <div class="avatar"> <?php if ( !empty( $avatar ) ) : ?> <img width="140" height="140" src="<?php echo esc_html( $avatar ); ?>"> <?php endif; ?> </div> <div class="name"> <?php echo $name; ?> </div> <div class="description"> <?php echo $description; ?> </div> <div class="user-profile"> <!-- Start Facebook --> <?php g_social($facebook_url, $facebook_icon, 'facebook.png'); ?> <!-- Start Twitter --> <?php g_social($twitter_url, $twitter_icon, 'twitter.png'); ?> <!-- Start Linkedin --> <?php g_social($linkedin_url, $linkedin_icon, 'linkedin.png'); ?> <!-- Start Instagram --> <?php g_social($instagram_url, $instagram_icon, 'instagram.png'); ?> <!-- Start Youtube --> <?php g_social($youtube_url, $youtube_icon, 'youtube.png'); ?> <!-- Start Pinterest --> <?php g_social($pinterest_url, $pinterest_icon, 'pinterest.png'); ?> <!-- Start TikTok --> <?php g_social($tiktok_url, $tiktok_icon, 'tiktok.png'); ?> <!-- End TikTok --> </div> <div class="links"> <?php foreach ( (array) $links as $key => $link ) : if ( empty( $link['image'] ) && empty( $link['url'] ) ) : ?> <div class="link"> </div> <?php elseif ( empty( $link['image'] )) : ?> <div class="link"> <a id="link_count" class="button link-without-image inline-photo show-on-scroll" href="<?php echo $link['url']; ?>" target="_blank" rel="noopener"> <span class="link-text"><?php echo $link['title']; ?></span> </a> </div> <?php else : ?> <div class="link"> <a id="link_count" class="button link-with-image inline-photo show-on-scroll" href="<?php echo $link['url']; ?>" target="_blank" rel="noopener"> <div class="thumbnail-wrap"> <img src="<?php echo $link['image']; ?>" class="link-image" alt="thumbnail"> </div> <span class="link-text"><?php echo $link['title']; ?></span> </a> </div> <?php endif; ?> <?php endforeach; ?> </div> </div> <?php wp_mylinks_track_mylink_page(get_the_ID()); ?> <?php endwhile; ?> <?php endif; ?> <footer id="site-footer" role="contentinfo" class="mylinks-footer"> <?php $enable_credits = get_option(sanitize_text_field('wp_mylinks_credits')); $credits = '<div class="wp-mylinks-credits">Made with ?? and ? by <a href="https://walterpinem.me" target="_blank" rel="noopener nofollow"><strong>Walter Pinem</strong></a></div>'; if ($enable_credits === 'yes') { echo $credits; } echo $footer_script; ?> </footer> </body> </html>
Viewing 1 replies (of 1 total)
- The topic ‘Support other SEO plugins’ is closed to new replies.