WordPress.org

Ready to get started?Download WordPress

Forums

How do I add to header ONLY on specific pages? + Adding Jquery (1 post)

  1. OM2
    Member
    Posted 3 years ago #

    I'm trying to write a plugin that needs to add to the header
    I don't want to add the header to every single page of the website - only on specific pages I choose
    I thought I could maybe do this using shortcodes - but it doesn't seem to be working

    This is what I have:

    <?php
    function myFunc()
    {
    	add_action("wp_head","myHeaderFunc");
    }
    
    function myHeaderFunc(){
    
    	echo <<<myStringEcho
    My header code goes here
    myStringEcho;
    }
    
    add_shortcode( 'myheader', 'myFunc' );
    ?>

    So, the intention is that if the user puts [myheader] on a page, the myHeaderFunc code gets called and added to the header with the add_action code

    NOTE: I've used <<< - does this cause a problem?

    I thought it was a neat solution!

    But not working

    Where am I going wrong?
    Can shortcodes be used in the way I have tried and do what I want?

    Thanks

    Omar

Topic Closed

This topic has been closed to new replies.

About this Topic