• Resolved mhd27

    (@mhd27)


    mikeshowlingdeals.com
    While `function add_before_content($content) {
    return ‘<a href=”www.mikeshowlingdeals.com/privacy-policy/”>The links in the post below may be affiliate links.</a>
    ‘.$content;
    }
    add_filter(‘the_content’, add_before_content);`
    shows the same text on every post, hyperlinked text only appears after clicking on a post title to go directly to the post. How do I get the predetermined text to be hyperlinked on all pages?

    Also, how do I do a line break on all pages? Just like the hyperlink, the line break only appears after clicking on a post title.

    I was told on the WordPress support forum that my “theme is using the_excerpt() in the index and archive pages;” and to ask here on how to change that. Thanks for any help.

Viewing 15 replies - 1 through 15 (of 15 total)
  • Theme Author Bishal Napit

    (@mebishalnapit)

    @mhd27

    Yes, this theme utilizes the excerpt display in the blog, archive and search pages. So, from the above code which you have provided, seems to be hooked in the the_content filter. Since it is hooked on that filter, it will be displayed in the content when it is opened up. So, to display that in the archive, blog and search pages, you need to simply replace the above the_content filter to the_excerpt filter and check. What I meant to say here is, you need to change:
    add_filter('the_content', 'add_before_content')
    to this one:
    add_filter('the_excerpt', 'add_before_content')

    And for the line break in those pages too, you need to manually edit those post and then enable the Excerpt option, which is usually under the Screen Options in the top right corner. After you check on the checkbox option of Excerpt, you will get the Excerpt option just below the post editor. Now, write anything there as you want to display the texts in the front-end.

    Thanks.

    Regards.
    Bishal Napit

    Thread Starter mhd27

    (@mhd27)

    Thanks for the reply. Replacing add_filter(‘the_content’, ‘add_before_content’) to add_filter(‘the_excerpt’, ‘add_before_content’) causes the website to go down though, and I have to edit functions.php and put back the default code.

    Theme Author Bishal Napit

    (@mebishalnapit)

    @mhd27

    Have you changed the code properly and closed the php codes in there properly? I am asking it since in my local environment, I have not got any of the issue on it and so, I have suggested it.

    Thanks.

    Regards.
    Bishal Napit

    Thread Starter mhd27

    (@mhd27)

    Sorry, I am new to all this. Does the code have to be something else than this? `function add_before_content($content) {
    return ‘<a href=”www.mikeshowlingdeals.com/privacy-policy/”>The links in the post below may be affiliate links.</a>
    ‘.$content;
    }
    add_filter(‘the_excerpt’, ‘add_before_content’);`

    Thanks.

    Theme Author Bishal Napit

    (@mebishalnapit)

    @mhd27

    The above provided code is the correct one. So, can you tell which error are you getting using that code in your site? Also, your link is linking to the page not found, ie, your site followed by the link added in that filter there. So, can you try this code and check:-

    function add_before_content($content) {
    return '<a href="https://www.mikeshowlingdeals.com/privacy-policy/">The links in the post below may be affiliate links.</a>
    '.$content;
    }
    add_filter('the_excerpt', 'add_before_content');

    Thanks.

    Regards.
    Bishal Napit

    Thread Starter mhd27

    (@mhd27)

    Thanks a lot; that code worked. https://www.mikeshowlingdeals.com/privacy-policy/? It works for me.

    Thread Starter mhd27

    (@mhd27)

    Oops, not resolved. I just noticed the hyperlink only appears on a page and not within a post. It doesn’t show up on the post when clicking on the title.

    Theme Author Bishal Napit

    (@mebishalnapit)

    @mhd27

    So, it seems that you like to add that link to the content page too. So, for this, you need to add that function to the the_content too, ie, what I meant to say is you need to add this code just below that above provided code:
    add_filter('the_content', 'add_before_content');
    So, the final code to be added in your child theme’s functions.php file will be:

    function add_before_content($content) {
    return '<a href="https://mikeshowlingdeals.com/privacy-policy/">The links in the post below may be affiliate links.</a>
    '.$content;
    }
    add_filter('the_excerpt', 'add_before_content');
    add_filter('the_content', 'add_before_content');

    If you like this theme and appreciate the effort in making this theme, they you can help via rating this theme.

    Thanks.

    Regards.
    Bishal Napit

    Thread Starter mhd27

    (@mhd27)

    That fixes the content page part, but now there’s two “The links in the post below may be affiliate links.” on the blog pages…one hyperlinked and one as text.

    Theme Author Bishal Napit

    (@mebishalnapit)

    @mhd27

    You can solve that issue via adding the Custom Excerpt for the post, which is already described above about how to do it in your site.

    Thanks.

    Regards.
    Bishal Napit

    Thread Starter mhd27

    (@mhd27)

    Is add_filter(‘the_excerpt’, ‘add_before_content’);
    already a custom excerpt? Because it is added. I left a theme review yesterday. Thanks for all the help.

    Theme Author Bishal Napit

    (@mebishalnapit)

    @mhd27

    The filter allows you to add the content in all of the posts, in the blog, archive and search pages. And it is also not the custom excerpt too.

    Adding the custom excerpt is already described above. But if you get confusion on adding the manual excerpt for the post, then, you can follow this link to add those: https://www.wpbeginner.com/plugins/how-to-customize-wordpress-excerpts-no-coding-required/

    Thanks.

    Regards.
    Bishal Napit

    Thread Starter mhd27

    (@mhd27)

    Oh, okay. I was hoping for the content to show up automatically after creating a post without me having to do anything. I have only found a plugin that still makes me have to click at the end of the text and press enter on each post. I just wanted to save time and not have to do that for every post. I’ll figure something out. Thanks for all the help.

    Theme Author Bishal Napit

    (@mebishalnapit)

    @mhd27

    It looks like you are trying to display the content too in the archive, search and blog pages, right? If yes, then, you can duplicate the file ‘template-parts/content.php’ in your child theme. In this file you will find the below code:

    <div class="entry-content">
        <?php
        if (is_single()) :
            the_content();
        else :
            if (is_sticky()) :
                // displaying full content for the sticky post
                the_content(sprintf(
                    /* translators: %s: Name of current post. */
                    wp_kses('<button type="button" class="btn btn-primary continue-more-link">' . __('Read More <i class="fa fa-arrow-circle-o-right"></i>', 'creative-blog') . '</button> %s', array('span' => array('class' => array()), 'i' => array('class' => array()), 'button' => array('class' => array(), 'type' => array()))), the_title('<span class="screen-reader-text">', '</span>', false)
                ));
            else :
                the_excerpt(); // displaying excerpt for the archive pages
            endif;
        endif;
        ?>
    
        <?php
        wp_link_pages(array(
            'before' => '<div class="page-links">' . esc_html__('Pages:', 'creative-blog'),
            'after' => '</div>',
        ));
        ?>
    </div><!-- .entry-content -->

    Now, you just need to change the above code with the below one and check:

    <div class="entry-content">
        <?php
        the_content(sprintf(
            /* translators: %s: Name of current post. */
            wp_kses('<button type="button" class="btn btn-primary continue-more-link">' . __('Read More <i class="fa fa-arrow-circle-o-right"></i>', 'creative-blog') . '</button> %s', array('span' => array('class' => array()), 'i' => array('class' => array()), 'button' => array('class' => array(), 'type' => array()))), the_title('<span class="screen-reader-text">', '</span>', false)
        ));
        ?>
        <?php
        wp_link_pages(array(
            'before' => '<div class="page-links">' . esc_html__('Pages:', 'creative-blog'),
            'after' => '</div>',
        ));
        ?>
    </div><!-- .entry-content -->

    Thanks.

    Regards.
    Bishal Napit

    Thread Starter mhd27

    (@mhd27)

    Thanks so much. That solved it! Sorry if I was not explaining things clearly before.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Hyperlink Predetermined Text on Every Post’ is closed to new replies.