WordPress.org

Ready to get started?Download WordPress

Forums

How to edit the URL's of the_content(read more) and comments_popup_link? (4 posts)

  1. boah123
    Member
    Posted 1 year ago #

    Hi,

    I would like to add google analytics params to the url's of the_content(read more) and comments_popup_link() function.

    Thus, after the url I would like to add "?utm_source= [..]"

    How can I do this?

    Thanks!

  2. bcworkz
    Member
    Posted 1 year ago #

    You can hook the filter 'the_content_more_link' to change the link for read more. There's no similar filter for popup links, all you can do there is add anchor attributes between class and title with 'comments_popup_link_attributes'.

  3. boah123
    Member
    Posted 1 year ago #

    Thanks for the reply!

    The problem is that I'm going to use the output for a newsletter, so I don't prefer to change WordPress functions. It would be nice if there is another way.

    Is it possible to remove the the_content(read more)-url at all? And then add it manually?

    Maybe this is also possible with the comments-url?

  4. bcworkz
    Member
    Posted 1 year ago #

    I think you can suppress the content more link by passing an empty string: the_content('');. But this is the link where you can alter the url parms, why do so manually?

    Not sure about popup comments, I don't use that style. It's probably initiated from a template file(s?). Doesn't sound like something you'd want to add manually. You could copy that file(s?) to a child theme and copy from the core file the comments_popup_link() function (with a new name) to the child's functions.php. Alter your version as needed to include the url parameter and have your child theme template call the altered function instead of the core.

    Or maybe a different analytics trigger would be easier to implement? I know little of the actual analytics mechanics, as you might be able to tell.

Topic Closed

This topic has been closed to new replies.

About this Topic