【问题标题】:wordpress twentyseventeen social media share icons without plugin advice needed.wordpress 二十七社交媒体共享图标,无需插件建议。
【发布时间】:2018-04-05 13:56:45
【问题描述】:

我很好奇将社交媒体 SVG 图标添加到页面和帖子类型(不使用插件)是否是最佳实践?

我在 WordPress 页面和帖子中添加了三个自定义字段。 facebook、twitter 和 google plus 字段 我添加了 WordPress 提供的 SVG 标签,这些标签特定于每个社交媒体网站。 wordpress page admin screenshot

这是我添加到首页的代码,我需要在其中添加社交分享图标

<header class="entry-header-hp">
                    <div class="page-title-homepage">
                    <?php the_title( '<h2 class="entry-title">', '</h2>' ); ?>
                    <nav class="social-naviation-news" role="navigation">
                        <div>
                            <ul>
                                <li>
                                    <a href="http://www.facebook.com/sharer/sharer.php?s=100&p[url]=<?php echo urlencode(get_permalink()); ?>" target="_blank"><?php echo the_field('facebook'); ?>
                                     </a>
                                </li>
                                <li>
                                    <a href="https://twitter.com/intent/tweet?text=<?php echo urlencode(get_the_title()); ?>+<?php echo get_permalink(); ?>" target="_blank">
                                   <?php echo the_field('twitter'); ?>
                                    </a>
                                </li>
                                <li>
                                   <a href="https://plus.google.com/share?url=<?php echo urlencode(get_permalink()); ?>" target="_blank">
                                   <?php echo the_field('Google'); ?>
                                    </a>
                               </li>
                            </ul>
                        </div>
                     </nav>
                    </div>
                    <div class="entry-meta">
                        <?php echo the_modified_date(); ?>
                    </div><!-- .entry-meta -->
                    <div class="edit-link">
                    <?php twentyseventeen_edit_link( get_the_ID() ); ?>
                    </div>
                </header><!-- .entry-header -->

如您所见,图标将显示在首页上。 https//staging.rockimages.com

这是一个好方法还是会导致任何问题?

【问题讨论】:

    标签: wordpress svg wordpress-theming custom-wordpress-pages social-media


    【解决方案1】:

    这不会导致问题,但我建议您以可重复使用的方式构建共享元素,并且不需要对多个页面模板进行批量更改。所以基本上用它制作一个函数并将它放在你的主题的functions.php 文件中。此外,如果您使用任何默认的 Wordpress 主题,请确保复制原始主题并重命名或创建子主题。

    参考:

    https://premium.wpmudev.org/blog/five-hacks-twenty-seventeen/#social https://premium.wpmudev.org/blog/how-to-create-wordpress-child-theme/

    【讨论】:

    • 感谢马斯克的快速回复。我也在使用儿童主题。我一直在尝试自学如何在 Wordpress 中创建 PHP 函数。我对 $args 在函数中的工作方式有点迷茫。您有任何 youtube 或教程建议吗?
    • Well 函数是典型的 PHP 函数。 add_action()、add_filters() 等。是另一个主题。那里有很多免费/付费的教程,所以我只用谷歌搜索没有发现任何问题。 StackOverflow 已经为您可能遇到的已经解决的问题提供了大量信息。除此之外,您需要学习这个平台,我希望您在学习的过程中玩得开心。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-05
    • 1970-01-01
    • 2019-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-09
    相关资源
    最近更新 更多