Divi WordPress Theme
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix Reply To: Where do I add code?

Discussion in 'Misc WordPress Requests' started by RossMitchell, Dec 15, 2017.

  1. RossMitchell


    Reply To: Where do I add code?, by RossMitchell

    I agree that it can be difficult to know what goes where on occasions.

    You should be doing this customisation in a child theme, details here:

    I see two different places you could place your code.
    A) In a custom page template, how the named templates get used is described here:
    First off include a big obvious tag that proves to you that your template is being accessed, something like: echo "<h2>Page Template TEST</h2>";

    B) Using a shortcode. Details here:
    Basically in your functions.php add code like this:

    function subcat17_func( $atts ){
    echo '<h2>In Function subcat17</h2>';
    $args = array('child_of' => 17);
    $categories = get_categories( $args );
    foreach($categories as $category) {
    echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
    echo '<p> Description:'. $category->description . '</p>';
    echo '<p> Post Count: '. $category->count . '</p>';
    add_shortcode( 'subcat17', 'subcat17_func' );

    Then in a page or post you can activate you code with [subcat17], again start with a proof of functionality.

    Reply To: Where do I add code?

Share This Page

Monarch Social Sharing Plugin