• Hi

    I’ve seen different variations of this question here, but mine is a bit more specific, so i would really appreciate if anyone can help me out.

    I would like to add this:
    Latest articles
    [Shortcode]
    below all of my blog posts without using a plugin and without doing it manually.

    I have tried several techniques i found on the internet with some code modifications but that resulted in crashing the website.

    “I do not know how to code or use php” so if anyone can give me a piece of a code that i could try that would be great ??

    Thank you very much

Viewing 8 replies - 1 through 8 (of 8 total)
  • You’d want to edit your theme’s functions.php file and use the filter “the_content”. The code to put at the end of the file would be something like this:

    function add_my_extra_content( $content ) {
    	$content .= '<p>Latest articles</p>';
    	$content .= '[shortcode]';
            return $content;
    }
    
    add_filter( 'the_content', 'add_my_extra_content' );
    Thread Starter atok2

    (@atok2)

    Thank you very much, this almost worked ??

    your code works but when i replace the [shortcode] with the actual shortcode, it crashes, any ideas why ?

    You can see here your code with the shortcode

    [ Moderator note: code fixed. Please wrap code in the backtick character or use the code button. ]

    function add_my_extra_content( $content ) {
    	$content .= '<p>Latest articles</p>';
    	$content .= '[ess_grid alias="Articles similaires" settings='{"max-entries":"4"}' special='related'][/ess_grid][ess_grid alias="Articles similaires" settings='{"max-entries":"4"}' special='related'][/ess_grid]';
            return $content;
    }
    
    add_filter( 'the_content', 'add_my_extra_content' );

    Try replacing the line that adds the shortcode with this:

    $content .= '[ess_grid alias="Articles similaires" settings=\'{"max-entries":"4"}\' special=\'related\'][/ess_grid][ess_grid alias="Articles similaires" settings=\'{"max-entries":"4"}\' special=\'related\'][/ess_grid]';
    Thread Starter atok2

    (@atok2)

    Sorry to not get back to you, i had a small problem to fix

    We are almost there, the code works but it is on posts and pages, How do i make them show up on only posts not pages, or even better on only certain categories “if it is not hard to do”

    thank you very very very much

    Hey atok I just put this together real quick so there’s probably a better way to do it, but for now this should work for you. In the “$included_cats” array you’d put the category id’s that you want to have the shortcode show up on.

    https://pastebin.com/AqLJPysQ

    Thread Starter atok2

    (@atok2)

    thank you very much Trey, ill try this as soon as get home

    just one question, to add the category id’s is this how i do that ?

    if ( $cat == $category->cat_ID ‘3’, ‘4’, ‘5’) {

    On line 6 of that pastebin:

    $included_cats = array( 0, 2, 10 );

    Replace the numbers with the category id’s you want the shortcode to show up on.

    $included_cats = array( 3, 4, 5 );

    That would work for 3 4 and 5. Say you wanted to add more you could do:

    $included_cats = array( 3, 4, 5, 10, 11 );

    And so on.

    Thread Starter atok2

    (@atok2)

    thank you very much for taking your time to write this

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘shortcode on all blog posts’ is closed to new replies.