skip to Main Content

How To Display Html In A Shortcode For A Specific Page –
The Page Is Woocommerce Shop Page
I addet the short code in widget and is not showing
need to show only for specific page

here is the code [rj_mysh]

function rj_mysh_shortcode() {
if(is_page(11762)) {
    $html = '<a href="example.com/script.php?id="></a>;
    return $html;
  }
}
add_shortcode('rj_mysh', 'rj_mysh_shortcode');

2

Answers


  1. The code looks like it will only show on page id = 11762.

    If it’s in a widget, it may not know it’s on page 11762, so it doesn’t display.

    It looks like you only want that item to appear in the widget area of page 11762. That’s a bit tricky.

    Solutions:

    • Alter the page layout so it includes the shortcode (easiest)
    • Set up a custom page template that includes a widget area. Use that template for this page, and put your widget in there. It would be like the regular page template, only with the other widget area.
    Login or Signup to reply.
  2. First of all, we are NOT gonna input html via the function.php file, never! (If you do I kill baby Yoda!). If you want to have real control the following is the best way.

    The right way to do it is to paste our custom "function" into the page-shop.php file.

    In your theme file, you should have a file called page-shop.php, upon opening it, bellow the header (anywhere you want, adapt it to the design) add the following:

    <?php
    /**
    * You can remplace the first line by the following line if you
    * want it to apply only on shop page that are not categories: 
    * if ( is_shop() && !is_product_category() ) {
    *
    *
    * Check if it's a shop page, and if it is do stuff...
    */
    if ( is_shop() ): ?>
    
    <div>My custom html goes here</div>
    
    <?php endif; ?>
    

    Hope that will help

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search